Skip to content

Commit

Permalink
fix: otp verification issue in knadh#23
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavxd committed Jan 27, 2022
1 parent 1031f29 commit 5aecb1e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions cmd/otpgateway/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ func handleOTPView(w http.ResponseWriter, r *http.Request) {
return
}

// Attempts are maxed out and locked.
if isLocked(out) {
// Attempts are maxed out and locked
if action != actCheck && isLocked(out) {
app.tpl.ExecuteTemplate(w, "message", webviewTpl{App: app.constants,
Title: "Too many attempts",
Description: fmt.Sprintf("Please retry after %d seconds.", int64(out.TTLSeconds)),
Expand Down Expand Up @@ -526,7 +526,7 @@ func verifyOTP(namespace, id, otp string, deleteOnVerify bool, app *App) (models
}

errMsg := ""
if isLocked(out) {
if isLocked(out) && !isFinalAttempt(out) {
errMsg = fmt.Sprintf("Too many attempts. Please retry after %0.f seconds.",
out.TTL.Seconds())
} else if out.OTP != otp {
Expand Down Expand Up @@ -595,10 +595,12 @@ func generateRandomString(totalLen int, chars string) (string, error) {

// isLocked tells if an OTP is locked after exceeding attempts.
func isLocked(otp models.OTP) bool {
if otp.Attempts >= otp.MaxAttempts {
return true
}
return false
return otp.Attempts >= otp.MaxAttempts
}

// isFinalAttempt checks if it's the final attempt
func isFinalAttempt(otp models.OTP) bool {
return otp.Attempts == otp.MaxAttempts
}

// push compiles a message template and pushes it to the provider.
Expand Down

0 comments on commit 5aecb1e

Please # to comment.