Browse Source

Fix error with entering unicode as a 2FA code

merge-requests/72/head
Deimos 6 years ago
parent
commit
7f806c9039
  1. 9
      tildes/tildes/models/user/user.py

9
tildes/tildes/models/user/user.py

@ -252,7 +252,14 @@ class User(DatabaseModel):
code = code.strip().replace(" ", "").lower()
if totp.verify(code):
# some possible user input (such as unicode) can cause an error in the totp
# library, catch that and treat it the same as an invalid code
try:
is_valid_code = totp.verify(code)
except TypeError:
is_valid_code = False
if is_valid_code:
return True
elif self.two_factor_backup_codes and code in self.two_factor_backup_codes:
# Need to set the attribute so SQLAlchemy knows it changed

Loading…
Cancel
Save