Skip to content

Commit

Permalink
Merge pull request #11 from tobiasmboelz/totp-valid-window
Browse files Browse the repository at this point in the history
TOTP_VALID_WINDOW setting
  • Loading branch information
xi authored Jun 23, 2022
2 parents b11147b + 72ddc03 commit f55050f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion mfa/methods/totp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def authenticate_complete(state, user, request_data):
keys = user.mfakey_set.filter(method=name)
for key in keys:
totp = pyotp.TOTP(key.secret)
if totp.verify(request_data) and request_data != key.last_code:
if (totp.verify(request_data, valid_window=settings.TOTP_VALID_WINDOW)
and request_data != key.last_code):
key.last_code = request_data
key.save()
return
Expand Down
4 changes: 4 additions & 0 deletions mfa/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@

# Available authentication methods in order of relevance
METHODS = getattr(settings, 'MFA_METHODS', ['FIDO2', 'TOTP', 'recovery'])

# `valid_window` parameter passed to PyOTP's verify method
# See https://pyauth.github.io/pyotp/#pyotp.totp.TOTP.verify
TOTP_VALID_WINDOW = getattr(settings, 'MFA_TOTP_VALID_WINDOW', 0)

0 comments on commit f55050f

Please sign in to comment.