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"
)
// Define the regex pattern as a constant
const (
pinPattern = `^\d{4}$`
// Define the regex pattern as a constant
pinPattern = `^\d{4}$`
//Allowed incorrect PIN attempts
AllowedPINAttempts = uint8(3)
)
// 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 {
err := h.countIncorrectPINAttempts(ctx, sessionId)
err := h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil {
return res, err
}
@ -884,7 +884,7 @@ func (h *Handlers) ShowBlockedAccount(ctx context.Context, sym string, input []b
code := codeFromCtx(ctx)
l := gotext.NewLocale(translationDir, code)
l.AddDomain("default")
res.Content = l.Get("Your account has been locked.For help on how to unblock your account,contact support at: 0757628885")
res.Content = l.Get("Your account has been locked.For help on how to unblock your account, contact support at: 0757628885")
return res, nil
}
@ -2124,8 +2124,8 @@ func (h *Handlers) UpdateAllProfileItems(ctx context.Context, sym string, input
return res, nil
}
// countIncorrectPINAttempts keeps track of the number of incorrect PIN attempts
func (h *Handlers) countIncorrectPINAttempts(ctx context.Context, sessionId string) error {
// incrementIncorrectPINAttempts keeps track of the number of incorrect PIN attempts
func (h *Handlers) incrementIncorrectPINAttempts(ctx context.Context, sessionId string) error {
var pinAttemptsCount uint8
store := h.userdataStore
@ -2163,8 +2163,8 @@ func (h *Handlers) resetIncorrectPINAttempts(ctx context.Context, sessionId stri
}
return err
}
remainingPINAttempts, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64)
if remainingPINAttempts <= uint64(common.AllowedPINAttempts) {
currentWrongPinAttemptsCount, _ := strconv.ParseUint(string(currentWrongPinAttempts), 0, 64)
if currentWrongPinAttemptsCount <= uint64(common.AllowedPINAttempts) {
err = store.WriteEntry(ctx, sessionId, common.DATA_INCORRECT_PIN_ATTEMPTS, []byte(string("0")))
if err != nil {
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 {
t.Logf(err.Error())
}
err = h.countIncorrectPINAttempts(ctx, sessionId)
err = h.incrementIncorrectPINAttempts(ctx, sessionId)
if err != nil {
t.Logf(err.Error())
}

View File

@ -54,7 +54,7 @@
},
{
"input": "1235",
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
"expectedContent": "Incorrect PIN. You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
},
{
"input": "1",
@ -95,7 +95,7 @@
},
{
"input": "1235",
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
"expectedContent": "Incorrect PIN. You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
},
{
"input": "1",
@ -140,7 +140,7 @@
},
{
"input": "1235",
"expectedContent": "Incorrect PIN.You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
"expectedContent": "Incorrect PIN. You have: 2 remaining attempt(s).\n1:Retry\n9:Quit"
},
{
"input": "1",

View File

@ -1 +1 @@
Incorrect PIN.You have: {{.reset_incorrect}} remaining attempt(s).
Incorrect PIN. You have: {{.reset_incorrect}} remaining attempt(s).

View File

@ -1 +1 @@
PIN ulioeka sio sahihi,una majaribio: {{.reset_incorrect}} yaliyobaki
PIN ulioeka sio sahihi, una majaribio: {{.reset_incorrect}} yaliyobaki

View File

@ -10,7 +10,7 @@ msgstr "Asante kwa kutumia huduma ya Sarafu. Kwaheri!"
msgid "For more help, please call: 0757628885"
msgstr "Kwa usaidizi zaidi, piga: 0757628885"
msgid "Your account has been locked.For help on how to unblock your account,contact support at: 0757628885"
msgid "Your account has been locked.For help on how to unblock your account, contact support at: 0757628885"
msgstr "Akaunti yako imefungwa.Kwa usaidizi wa jinsi ya kufungua akaunti yako, wasiliana na usaidizi kwa: 0757628885"
msgid "Balance: %s\n"