<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Junimdv on Medium]]></title>
        <description><![CDATA[Stories by Junimdv on Medium]]></description>
        <link>https://medium.com/@juni313786?source=rss-d85b65543d18------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*0YF5-Un6AXGe44EN</url>
            <title>Stories by Junimdv on Medium</title>
            <link>https://medium.com/@juni313786?source=rss-d85b65543d18------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:31:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@juni313786/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Implementing Password Reset in Go: Tokens, APIs, and Security]]></title>
            <link>https://medium.com/@juni313786/implementing-password-reset-in-go-tokens-apis-and-security-8b6b9e6eae72?source=rss-d85b65543d18------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b6b9e6eae72</guid>
            <dc:creator><![CDATA[Junimdv]]></dc:creator>
            <pubDate>Tue, 05 May 2026 06:19:33 GMT</pubDate>
            <atom:updated>2026-05-05T06:57:26.176Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first started working on authentication parts in my personal project, I underestimated the complexity of the forgot password feature. I assumed it was just another endpoint — something that could be implemented quickly without much thought.</p><p>But once I began designing it properly, I realized it involves much more than sending a reset link. It requires careful handling of tokens, secure validation, protection against attacks, and proper system design to make it reliable in production.</p><p>In this article, I’ll share my journey of building a forgot password system using Go — from initial assumptions to a more secure and structured implementation. Along the way, I’ll explain the design choices, common pitfalls, and best practices that helped shape the final solution.<br> When implementing the forgot password feature, I explored multiple approaches before settling on a final design. The most common method is a link-based reset flow, where a user clicks a URL sent to their email and directly sets a new password.</p><p>In this approach, the system generates a token, embeds it in a reset link, and sends it to the user’s email. When the user clicks the link, they are redirected to a password reset page where the token is validated before allowing the password update.</p><p>However, I decided to implement a different approach — an OTP-based reset flow combined with JWT authentication for better control and security.</p><p>In my implementation, when a user requests a password reset, an OTP is sent to their registered email. The user must first verify this OTP. Upon successful verification, the system generates a short-lived JWT token specifically for password reset purposes. This token is sent as a secure cookie to the user.</p><p>The user can then submit a new password and confirm password, and the system validates the request using this reset token. Once verified, the password is updated, and the token is invalidated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ohc7nC284lZXt5eXOXLgKg.png" /><figcaption>implementation flow</figcaption></figure><pre>// Rest handlers methods in api gateway part <br><br>func (uh *authHandler) ResendOtp(c *gin.Context) {<br> ctx, cancel := context.WithTimeout(c.Request.Context(), *uh.timeout)<br> defer cancel()<br><br> var req dtos.ResentOtpReq<br> if err := c.BindJSON(&amp;req); err != nil {<br>  response.ErrResponse(c, http.StatusBadRequest, &quot;invalid request playload&quot;, err.Error)<br>  return<br> }<br><br> res, err := uh.client.ResendOtp(ctx, &amp;pb.ResendOtpReq{<br>  Email:   req.Email,<br>  OtpType: req.OtpType,<br> })<br><br> if err != nil {<br>  response.HandleGRPCError(c, err)<br>  return<br> }<br><br> response.SuccessResponse(c, http.StatusOK, &quot;otp resent successfully&quot;, &amp;dtos.ResentOtpResponse{<br>  OtpStatus: res.Success,<br>  OtpExpiry: res.OtpExpiry.AsTime(),<br> })<br><br>}<br><br>func (uh *authHandler) ForgotPassword(c *gin.Context) {<br> ctx, cancel := context.WithTimeout(c.Request.Context(), *uh.timeout)<br> defer cancel()<br> var req dtos.ForgotPasswordRequest<br> if err := c.BindJSON(&amp;req); err != nil {<br>  response.ErrResponse(c, http.StatusBadRequest, &quot;invalid request playload&quot;, err.Error)<br>  return<br> }<br><br> res, err := uh.client.ForgotPassword(ctx, &amp;pb.ForgotPasswordReq{<br>  Email: req.Email,<br> })<br><br> if err != nil {<br>  response.HandleGRPCError(c, err)<br>  return<br> }<br> response.SuccessResponse(c, http.StatusOK, &quot;otp resent successfully&quot;, &amp;dtos.ForgotPasswordResponse{<br>  OtpStatus:  res.Success,<br>  ExpirestAt: res.OtpExpiry.AsTime(),<br> })<br><br>}<br><br>func (uh *authHandler) VerifyForgotPassword(c *gin.Context) {<br> ctx, cancel := context.WithTimeout(c.Request.Context(), *uh.timeout)<br> defer cancel()<br><br> var req *dtos.VerifyForgotPasswordOtpReq<br> if err := c.BindJSON(&amp;req); err != nil {<br>  response.ErrResponse(c, http.StatusBadRequest, &quot;invalid request playload&quot;, err.Error)<br>  return<br> }<br> res, err := uh.client.VerifyForgotPassword(ctx, &amp;pb.VerifyForgotPasswordReq{<br>  Email: req.Email,<br>  Otp:   req.Otp,<br> })<br><br> if err != nil {<br>  response.HandleGRPCError(c, err)<br>  return<br> }<br><br> uh.cookie.SetCookie(c, config.ResetPasswordToken, res.ResetToken, res.ResetTokenExpiry.AsTime())<br><br> response.SuccessResponse(c, http.StatusOK, &quot;otp resent successfully&quot;, &amp;dtos.VerifyForgotPasswordOtpResponse{<br>  Success:          res.Success,<br>  ResetTokenExpiry: res.ResetTokenExpiry.AsTime(),<br> })<br><br>}<br><br>func (uh *authHandler) ResetPassword(c *gin.Context) {<br> ctx, cancel := context.WithTimeout(c.Request.Context(), *uh.timeout)<br> defer cancel()<br><br> var req dtos.ResetPasswordReq<br> if err := c.BindJSON(&amp;req); err != nil {<br>  response.ErrResponse(c, http.StatusBadRequest, &quot;invalid request playload&quot;, err.Error())<br>  return<br> }<br><br> resetToken, err := uh.cookie.GetCookie(c, config.ResetPasswordToken)<br> if err != nil {<br>  response.ErrResponse(c, http.StatusUnauthorized, &quot;missing reset token&quot;, &quot;&quot;)<br>  return<br> }<br><br><br> _, err = uh.client.ResetPassword(ctx, &amp;pb.ResetPasswordReq{<br>  Email:           req.Email,<br>  Password:        req.Password,<br>  ConfirmPassword: req.ConfirmPassword,<br>  ResetToken:      resetToken,<br> })<br><br> if err != nil {<br>  response.HandleGRPCError(c, err)<br>  return<br> }<br><br> uh.cookie.DeleteCookie(c, config.ResetPasswordToken)<br><br> response.SuccessResponse(c, http.StatusOK, &quot;password reset successfull&quot;, &quot;&quot;)<br><br>}</pre><pre> //grpc handler for forgotPassword <br>func (uh *authHandler) ForgotPassword(ctx context.Context, pb *pb.ForgotPasswordReq) (*pb.ForgotPasswordRes, error) {<br> ctx, cancel := context.WithTimeout(ctx, *uh.timeout)<br> defer cancel()<br><br> request := dt.ToForgotPasswordReq(pb)<br><br> if validationErrs := uh.validater.Validation(request); validationErrs != nil {<br>  stWithDetails, err := ValidationError(validationErrs)<br>  if err != nil {<br>   return nil, status.Error(codes.InvalidArgument, &quot;failed to attach details&quot;)<br>  }<br>  return nil, stWithDetails.Err()<br> }<br><br> res, err := uh.authUseCase.ForgotPassword(ctx, &amp;ucdtos.ForgotPasswordReq{<br>  Email: request.Email,<br> })<br> if err != nil {<br>  return nil, domain.GRPCStatus(err)<br> }<br><br> return dt.ToForgotPasswordRes(res), nil<br>}<br> //verify  forgot password <br>func (uh *authHandler) VerifyForgotPassword(ctx context.Context, pb *pb.VerifyForgotPasswordReq) (*pb.VerifyForgotPasswordRes, error) {<br> ctx, cancel := context.WithTimeout(ctx, *uh.timeout)<br> defer cancel()<br><br> request := dt.ToVerifyForgotPasswordOtpReq(pb)<br><br> if validationErrs := uh.validater.Validation(request); validationErrs != nil {<br>  stWithDetails, err := ValidationError(validationErrs)<br>  if err != nil {<br>   return nil, status.Error(codes.InvalidArgument, &quot;failed to attach details&quot;)<br>  }<br>  return nil, stWithDetails.Err()<br> }<br><br> res, err := uh.authUseCase.VerifyForgotPasswordOtp(ctx, &amp;ucdtos.VerifyForgotPasswordOtpReq{<br>  Email: request.Email,<br>  Otp:   request.Otp,<br> })<br><br> if err != nil {<br>  return nil, domain.GRPCStatus(err)<br> }<br><br> return dt.ToVerifyForgotPasswordOtpRes(res), nil<br>}<br><br><br>func (uh *authHandler) ResetPassword(ctx context.Context, pb *pb.ResetPasswordReq) (*pb.ResetPasswordRes, error) {<br> ctx, cancel := context.WithTimeout(ctx, *uh.timeout)<br> defer cancel()<br><br> request := dt.ToResetPasswordReq(pb)<br><br> if validationErrs := uh.validater.Validation(request); validationErrs != nil {<br>  stWithDetails, err := ValidationError(validationErrs)<br>  if err != nil {<br>   return nil, status.Error(codes.InvalidArgument, &quot;failed to attach details&quot;)<br>  }<br>  return nil, stWithDetails.Err()<br> }  <br><br> uh.logger.Info(&quot;reset token data&quot;,&quot;data&quot;,request,&quot;token&quot;,request.ResetToken)<br><br> res, err := uh.authUseCase.ResetPassword(ctx, &amp;ucdtos.ResetPasswordReq{<br>  Email:    request.Email,<br>  Password: request.Password,<br> })<br><br> if err != nil {<br>  return nil, domain.GRPCStatus(err)<br> }<br> return dt.ToResetPasswordRes(res), nil<br>}<br><br>func (uh *authHandler) RenweAccessToken(ctx context.Context, pb *pb.RenewAccessTokenReq) (*pb.RenewAccessTokenRes, error) {<br> ctx, cancel := context.WithTimeout(ctx, *uh.timeout)<br> defer cancel()<br><br> request := dt.ToRenewAccessTokenReq(pb)<br><br> if validationErrs := uh.validater.Validation(request); validationErrs != nil {<br>  stWithDetails, err := ValidationError(validationErrs)<br>  if err != nil {<br>   return nil, status.Error(codes.InvalidArgument, &quot;failed to attach details&quot;)<br>  }<br>  return nil, stWithDetails.Err()<br> }<br><br> res, err := uh.authUseCase.RenewAccessToken(ctx, &amp;ucdtos.RenewAcccessTokenReq{<br>  RefreshToken: request.RefreshToken,<br> })<br> if err != nil {<br>  return nil, domain.GRPCStatus(err)<br> }<br> return dt.ToRenewAccessTokenRes(res), nil<br>}<br><br>//usecase layer with forgot password methods <br><br>func (uc *authUsecase) ForgotPassword(ctx context.Context, input *uc_dtos.ForgotPasswordReq) (*uc_dtos.ForgotPasswordRes, error) {<br> exist, err := uc.userRepo.CheckEmailExist(ctx, input.Email)<br> if err != nil {<br>  return nil, err<br> }<br><br> if !exist {<br>  return nil, domain.NewNotFoundError(&quot;email not found.User registered email&quot;)<br> }<br><br> otp, err := uc.email.SendOTP(input.Email)<br> if err != nil {<br>  return nil, uc.email.MapMailError(err)<br> }<br><br> otpExpiredAt := time.Now().Add(otp.Expiry)<br><br> otpdata, err := uc.userRepo.AddOtpData(ctx, &amp;entity.Otp{<br>  Email:     input.Email,<br>  Otp:       otp.Otp,<br>  Type:      string(entity.ForgotPassword),<br>  Attempts:  0,<br>  ExpiresAt: otpExpiredAt,<br> })<br> if err != nil {<br>  return nil, err<br> }<br><br> uc.logger.Info(&quot;otp data added in db&quot;, &quot;data&quot;, otpdata)<br><br> return &amp;uc_dtos.ForgotPasswordRes{<br>  Success:   true,<br>  ExpiresAt: otpExpiredAt,<br> }, nil<br>}<br><br>func (uc *authUsecase) VerifyForgotPasswordOtp(ctx context.Context, input *uc_dtos.VerifyForgotPasswordOtpReq) (*uc_dtos.VerifyForgotPasswordOtpRes, error) {<br> exist, err := uc.userRepo.CheckEmailExist(ctx, input.Email)<br> if err != nil {<br>  return nil, err<br> }<br><br> if !exist {<br>  return nil, domain.NewNotFoundError(&quot;email not found.User registered email&quot;)<br> }<br><br> otpRecord, err := uc.userRepo.GetLatestOtpRecord(ctx, input.Email, entity.ForgotPassword)<br> if err != nil {<br>  return nil, err<br> }<br> if otpRecord.Attempts == entity.OtpMaxAttempts {<br>  return nil, domain.NewUnAuthenticatedError(&quot;OTP has reached max attempt.Resend otp&quot;)<br> }<br><br> if time.Now().After(otpRecord.ExpiresAt) {<br>  return nil, domain.NewUnAuthenticatedError(&quot;OTP expired.Resent otp&quot;)<br> }<br><br> if otpRecord.Otp != input.Otp {<br><br>  if err := uc.userRepo.UpdateOtpAttempts(ctx, input.Email, entity.Register); err != nil {<br>   return nil, err<br>  }<br>  return nil, domain.NewUnAuthenticatedError(&quot;Invalid otp.&quot;)<br> }<br><br> if err := uc.userRepo.DeleteOtp(ctx, otpRecord.ID); err != nil {<br>  return nil, err<br> }<br><br> uc.logger.Info(&quot;forgot password otp verified&quot;, &quot;email&quot;, input.Email)<br><br> user, err := uc.userRepo.GetUserByEmail(ctx, input.Email)<br> if err != nil {<br>  return nil, err<br> }<br><br> token, resetTokeClaims, err := uc.token.GenerateToken(user.Id, user.Email, &quot;reset&quot;, uc.token.ResetPasswordTokenExpirty)<br> if err != nil {<br>  uc.logger.Error(&quot;failed generate token&quot;, &quot;method&quot;, &quot;verify forget password&quot;, &quot;layer&quot;, &quot;usecase&quot;)<br>  return nil, domain.NewInternalError(&quot;Something went wrong. Please try again later.&quot;, err)<br> }<br><br> return &amp;uc_dtos.VerifyForgotPasswordOtpRes{<br>  Success:    true,<br>  ResetToken: token,<br>  ExpiresAt:  resetTokeClaims.ExpiresAt.Time,<br> }, nil<br><br>}<br><br>func (uc *authUsecase) ResetPassword(ctx context.Context, input *uc_dtos.ResetPasswordReq) (*uc_dtos.ResetPasswordRes, error) {<br><br> if input.ResetToken == &quot;&quot; {<br>  uc.logger.Warn(&quot;invalid token&quot;, &quot;error&quot;, &quot;reset token is missing&quot;)<br>  return nil, domain.NewUnAuthenticatedError(&quot;missing reset token&quot;)<br> }<br><br> claims, err := uc.token.VerifyToken(input.ResetToken)<br> if err != nil {<br>  uc.logger.Warn(&quot;invalid reset token&quot;, &quot;method&quot;, &quot;ResetPassword&quot;, &quot;error&quot;, err)<br>  return nil, err<br> }<br><br> if claims.Role != &quot;reset&quot; {<br>  uc.logger.Warn(&quot;invalid otp&quot;, &quot;error&quot;, &quot;invalid role&quot;, &quot;method&quot;, &quot;reset password&quot;)<br>  return nil, domain.NewUnAuthenticatedError(&quot;invalid otp&quot;)<br> }<br><br> hashedPassword, err := uc.hash.HashPassword(input.Password)<br> if err != nil {<br>  uc.logger.Error(&quot;Failed hash password&quot;, &quot;method&quot;, &quot;ResetPassword&quot;, &quot;error&quot;, err)<br>  return nil, domain.NewInternalError(&quot;Something went wrong. Please try again later&quot;, err)<br> }<br><br> if err := uc.userRepo.UpdatePassword(ctx, claims.Email, hashedPassword); err != nil {<br>  return nil, err<br> }<br><br> return &amp;uc_dtos.ResetPasswordRes{<br>  Success: true,<br> }, nil<br>}<br><br>func (uc *authUsecase) RenewAccessToken(ctx context.Context, input *uc_dtos.RenewAcccessTokenReq) (*uc_dtos.RenewAccessTokenRes, error) {<br> claims, err := uc.token.VerifyToken(input.RefreshToken)<br> if err != nil {<br>  return nil, err<br> }<br><br> key := &quot;session:&quot; + claims.ID<br><br> sessiondata, err := uc.session.GetSession(ctx, key)<br> if err != nil {<br>  return nil, err<br> }<br><br> isRevoked, _ := strconv.ParseBool(sessiondata.IsRevoked)<br> if isRevoked {<br>  uc.logger.Info(&quot;invalid token&quot;, &quot;error&quot;, &quot;user token revoked&quot;)<br>  return nil, domain.NewUnAuthenticatedError(&quot;Invalid refresh token.Please login again&quot;)<br> }<br><br> if sessiondata.UserEmail != claims.Email {<br>  uc.logger.Warn(&quot;invalid token&quot;, &quot;error&quot;, errors.New(&quot;token email mismatch&quot;))<br>  return nil, domain.NewUnAuthenticatedError(&quot;Invalid refresh token. Please login again&quot;)<br> }<br><br> accessToken, accessClaims, err := uc.token.GenerateToken(sessiondata.ID, sessiondata.UserEmail, claims.Role, uc.token.AccessTokenExpiry)<br> if err != nil {<br>  return nil, err<br> }<br><br> return &amp;uc_dtos.RenewAccessTokenRes{<br>  AccessToken:       accessToken,<br>  AccessTokenExpiry: accessClaims.ExpiresAt.Time,<br> }, nil<br><br>}</pre><pre>//implementation send otp through email using gomail package. <br>package otp<br><br>import (<br> &quot;crypto/rand&quot;<br> &quot;fmt&quot;<br> &quot;log&quot;<br> &quot;math/big&quot;<br> &quot;time&quot;<br><br> &quot;github.com/Junaidmdv/goalcircle-user_service/internal/config&quot;<br> &quot;gopkg.in/gomail.v2&quot;<br>)<br><br>type EmailService struct {<br> *gomail.Dialer<br> OtpExpiry  time.Duration<br> MaxAttempt uint<br>}<br><br>type OtpResponse struct {<br> Otp    string<br> Expiry time.Duration<br>}<br><br>// Constructor<br>func NewEmailService(cfg *config.SMTPConfig) (*EmailService, error) {<br> return &amp;EmailService{<br>  Dialer: &amp;gomail.Dialer{<br>   Host:     cfg.ServerURL,<br>   Port:     cfg.Port,<br>   Username: cfg.FromEmail,<br>   Password: cfg.Password,<br>   SSL:      cfg.Port == 465,<br>  },<br>  OtpExpiry:  cfg.OtpExpiry,<br>  MaxAttempt: uint(cfg.MaxAttempt),<br> }, nil<br>}<br><br>// Generate secure 6-digit OTP<br>func (e *EmailService) GenerateOTP(length int) (string, error) {<br> max := new(big.Int).Exp(big.NewInt(10), big.NewInt(int64(length)), nil)<br> n, err := rand.Int(rand.Reader, max)<br> if err != nil {<br>  return &quot;&quot;, err<br> }<br> return fmt.Sprintf(&quot;%0*d&quot;, length, n), nil<br><br>}<br><br>// Send OTP email<br>func (e *EmailService) SendOTP(toEmail string) (*OtpResponse, error) {<br> otp, err := e.GenerateOTP(6)<br> if err != nil {<br>  return nil, err<br> }<br> log.Printf(&quot;%v username&quot;, e.Username)<br><br> m := gomail.NewMessage()<br> m.SetHeader(&quot;From&quot;, e.Username)<br> m.SetHeader(&quot;To&quot;, toEmail)<br> m.SetHeader(&quot;Subject&quot;, &quot;Your OTP Verification Code&quot;)<br> m.SetBody(&quot;text/html&quot;, fmt.Sprintf(`<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;<br>&lt;/head&gt;<br>&lt;body style=&quot;margin:0;padding:0;background-color:#f4f6f9;font-family:Arial,sans-serif;&quot;&gt;<br><br>  &lt;table width=&quot;100%%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-color:#f4f6f9;padding:40px 0;&quot;&gt;<br>    &lt;tr&gt;<br>      &lt;td align=&quot;center&quot;&gt;<br>        &lt;table width=&quot;480&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-color:#ffffff;border-radius:12px;overflow:hidden;border:1px solid #e8eaed;&quot;&gt;<br><br>          &lt;!-- Header --&gt;<br>          &lt;tr&gt;<br>            &lt;td style=&quot;background-color:#185FA5;padding:32px;text-align:center;&quot;&gt;<br>              &lt;h1 style=&quot;margin:0;color:#ffffff;font-size:22px;font-weight:600;letter-spacing:0.5px;&quot;&gt;<br>                Password Reset<br>              &lt;/h1&gt;<br>              &lt;p style=&quot;margin:8px 0 0;color:#b3d4f0;font-size:13px;&quot;&gt;<br>                One-Time Password Verification<br>              &lt;/p&gt;<br>            &lt;/td&gt;<br>          &lt;/tr&gt;<br><br>          &lt;!-- Body --&gt;<br>          &lt;tr&gt;<br>            &lt;td style=&quot;padding:40px 32px 24px;&quot;&gt;<br>              &lt;p style=&quot;margin:0 0 8px;color:#1a1a2e;font-size:16px;font-weight:600;&quot;&gt;<br>                Hello,<br>              &lt;/p&gt;<br>              &lt;p style=&quot;margin:0 0 28px;color:#555770;font-size:14px;line-height:1.6;&quot;&gt;<br>                We received a request to reset your password. Use the OTP below to proceed.<br>                This code is valid for &lt;strong style=&quot;color:#185FA5;&quot;&gt;10 minutes&lt;/strong&gt; and can only be used once.<br>              &lt;/p&gt;<br><br>              &lt;!-- OTP Box --&gt;<br>              &lt;table width=&quot;100%%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;<br>                &lt;tr&gt;<br>                  &lt;td align=&quot;center&quot;&gt;<br>                    &lt;div style=&quot;background-color:#f0f6ff;border:1.5px dashed #185FA5;border-radius:12px;padding:28px 0;margin-bottom:28px;&quot;&gt;<br>                      &lt;p style=&quot;margin:0 0 8px;color:#888;font-size:12px;letter-spacing:1px;text-transform:uppercase;&quot;&gt;<br>                        Your OTP Code <br>                      &lt;/p&gt;<br>                      &lt;p style=&quot;margin:0;font-size:42px;font-weight:700;letter-spacing:16px;color:#185FA5;padding-left:16px;&quot;&gt;<br>                        %s<br>                      &lt;/p&gt;<br>                    &lt;/div&gt;<br>                  &lt;/td&gt;<br>                &lt;/tr&gt;<br>              &lt;/table&gt;<br><br>              &lt;!-- Warning --&gt;<br>              &lt;table width=&quot;100%%&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;&gt;<br>                &lt;tr&gt;<br>                  &lt;td style=&quot;background-color:#fff8f0;border-left:4px solid #EF9F27;border-radius:0 8px 8px 0;padding:12px 16px;margin-bottom:24px;&quot;&gt;<br>                    &lt;p style=&quot;margin:0;color:#854F0B;font-size:13px;line-height:1.5;&quot;&gt;<br>                      &lt;strong&gt;Security Notice:&lt;/strong&gt; Never share this OTP with anyone.<br>                      Our team will never ask for your OTP.<br>                    &lt;/p&gt;<br>                  &lt;/td&gt;<br>                &lt;/tr&gt;<br>              &lt;/table&gt;<br>            &lt;/td&gt;<br>          &lt;/tr&gt;<br><br>          &lt;!-- Divider --&gt;<br>          &lt;tr&gt;<br>            &lt;td style=&quot;padding:0 32px;&quot;&gt;<br>              &lt;hr style=&quot;border:none;border-top:1px solid #f0f0f0;margin:0;&quot;&gt;<br>            &lt;/td&gt;<br>          &lt;/tr&gt;<br><br>          &lt;!-- Footer --&gt;<br>          &lt;tr&gt;<br>            &lt;td style=&quot;padding:24px 32px;text-align:center;&quot;&gt;<br>              &lt;p style=&quot;margin:0 0 4px;color:#aaa;font-size:12px;&quot;&gt;<br>                If you didn&#39;t request a password reset, please ignore this email.<br>              &lt;/p&gt;<br>              &lt;p style=&quot;margin:0;color:#aaa;font-size:12px;&quot;&gt;<br>                This OTP will expire automatically after 10 minutes.<br>              &lt;/p&gt;<br>            &lt;/td&gt;<br>          &lt;/tr&gt;<br><br>        &lt;/table&gt;<br>      &lt;/td&gt;<br>    &lt;/tr&gt;<br>  &lt;/table&gt;<br><br>&lt;/body&gt;<br>&lt;/html&gt;<br> `, otp))<br><br> if err := e.DialAndSend(m); err != nil {<br>  return nil, err<br> }<br><br> return &amp;OtpResponse{<br>  Otp:    otp,<br>  Expiry: e.OtpExpiry,<br> }, nil<br>}</pre><p>This approach provides a more controlled flow with explicit verification steps, reduces the risk of token leakage through URLs, and allows better handling of session-like validation using cookies.</p><p>In the following sections, I will break down this design, the reasoning behind it, and how it can be implemented securely in a production-grade backend system using Go.<br>## 🔗 GitHub Repository</p><p>The complete implementation is organized as a microservices-based system with separate repositories for the API Gateway and the User Service:</p><p>👉 API Gateway (Gin): <a href="https://github.com/Junaidmdv/goalcircle-user_service.git">https://github.com/Junaidmdv/goalcircle-user_service.git</a><br>👉 User Service (gRPC): <a href="https://github.com/Junaidmdv/goalcircle-user_service.git">https://github.com/Junaidmdv/goalcircle-user_service.git</a><br>This project follows a microservices architecture using gRPC for inter-service communication and Gin as the API Gateway. The implementation is structured using Clean Architecture principles and adheres to SOLID design practices.</p><p>It includes:</p><p>* OTP generation and verification flow<br>* JWT-based reset token using secure cookies<br>* Password reset logic with proper validation<br>* Layered architecture (handler → usecase → repository)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b6b9e6eae72" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>