Skip to content

Commit 274c614

Browse files
committed
refactor: standardize MFA defaults
1 parent 9757805 commit 274c614

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

services/mfa/server.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const (
1919
defaultSessionTimeout = 5 * time.Minute
2020
defaultCodeLength = 6
2121
defaultMaxAttempts = 3
22+
zeroDuration = 0 * time.Second
23+
zeroCodeLength = 0
24+
initialAttemptCount = 0
2225
challengeTemplate = "Enter the %d-digit code sent to your registered device"
2326
headerContentType = "Content-Type"
2427
contentTypeJSON = "application/json"
@@ -75,10 +78,10 @@ type VerifyRequest struct {
7578

7679
// New creates a new MFA server
7780
func New(cfg Config) *Server {
78-
if cfg.SessionTimeout <= 0 {
81+
if cfg.SessionTimeout <= zeroDuration {
7982
cfg.SessionTimeout = defaultSessionTimeout
8083
}
81-
if cfg.CodeLength <= 0 {
84+
if cfg.CodeLength <= zeroCodeLength {
8285
cfg.CodeLength = defaultCodeLength
8386
}
8487

@@ -150,7 +153,7 @@ func (s *Server) challengeHandler(w http.ResponseWriter, r *http.Request) {
150153
Challenge: fmt.Sprintf(challengeTemplate, codeDigits),
151154
Code: code,
152155
ExpiresAt: time.Now().Add(s.cfg.SessionTimeout),
153-
Attempts: 0,
156+
Attempts: initialAttemptCount,
154157
MaxAttempts: defaultMaxAttempts,
155158
}
156159

0 commit comments

Comments
 (0)