diff --git a/apps/authentication/mfa/base.py b/apps/authentication/mfa/base.py index b7f7ae4ee..98cdf415f 100644 --- a/apps/authentication/mfa/base.py +++ b/apps/authentication/mfa/base.py @@ -1,5 +1,6 @@ import abc +from django.conf import settings from django.core.cache import cache from django.utils.translation import gettext_lazy as _ @@ -23,17 +24,22 @@ class BaseMFA(abc.ABC): cache_key = f'{self.name}_{self.user.username}' cache_code = cache.get(cache_key) - if cache_code == code: - return False, _( - "The two-factor code you entered has either already been used or has expired. " - "Please request a new one." - ) + + is_match = cache_code == code + if is_match: + if not settings.SAFE_MODE: + return True, '' + else: + return False, _( + "The two-factor code you entered has either already been used or has expired. " + "Please request a new one." + ) ok, msg = self._check_code(code) if not ok: return False, msg - cache.set(cache_key, code, 60 * 5) + cache.set(cache_key, code, 60) return True, msg def is_authenticated(self):