Compare commits

..

4 Commits

7 changed files with 18 additions and 15 deletions

View File

@ -6,10 +6,13 @@ import (
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
// Define the regex pattern as a constant
const ( const (
// Define the regex pattern as a constant
pinPattern = `^\d{4}$` pinPattern = `^\d{4}$`
//Allowed incorrect PIN attempts
AllowedPINAttempts = uint8(3) AllowedPINAttempts = uint8(3)
) )
// checks whether the given input is a 4 digit number // checks whether the given input is a 4 digit number

View File

@ -747,7 +747,7 @@ func (h *Handlers) Authorize(ctx context.Context, sym string, input []byte) (res
} }
} }
} else { } else {
err := h.countIncorrectPINAttempts(ctx, sessionId) err := h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil { if err != nil {
return res, err return res, err
} }
@ -2124,8 +2124,8 @@ func (h *Handlers) UpdateAllProfileItems(ctx context.Context, sym string, input
return res, nil return res, nil
} }
// countIncorrectPINAttempts keeps track of the number of incorrect PIN attempts // incrementIncorrectPINAttempts keeps track of the number of incorrect PIN attempts
func (h *Handlers) countIncorrectPINAttempts(ctx context.Context, sessionId string) error { func (h *Handlers) incrementIncorrectPINAttempts(ctx context.Context, sessionId string) error {
var pinAttemptsCount uint8 var pinAttemptsCount uint8
store := h.userdataStore store := h.userdataStore
@ -2163,8 +2163,8 @@ func (h *Handlers) resetIncorrectPINAttempts(ctx context.Context, sessionId stri
} }
return err return err
} }
remainingPINAttempts, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64) currentWrongPinAttemptsCount, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64)
if remainingPINAttempts <= uint64(common.AllowedPINAttempts) { if currentWrongPinAttemptsCount <= uint64(common.AllowedPINAttempts) {
err = store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(string("0"))) err = store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(string("0")))
if err != nil { if err != nil {
logg.ErrorCtxf(ctx, "failed to reset incorrect PIN attempts ", "key", common.DATA_INCORRECT_PIN_ATTEMPTS, "value", common.AllowedPINAttempts, "error", err) logg.ErrorCtxf(ctx, "failed to reset incorrect PIN attempts ", "key", common.DATA_INCORRECT_PIN_ATTEMPTS, "value", common.AllowedPINAttempts, "error", err)

View File

@ -2247,7 +2247,7 @@ func TestCountIncorrectPINAttempts(t *testing.T) {
if err != nil { if err != nil {
t.Logf(err.Error()) t.Logf(err.Error())
} }
err = h.countIncorrectPINAttempts(ctx, sessionId) err = h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil { if err != nil {
t.Logf(err.Error()) t.Logf(err.Error())
} }