Update 2FA

This commit is contained in:
MacRimi
2026-02-13 10:51:27 +01:00
parent 00230d1b8f
commit c89baf34a8
2 changed files with 14 additions and 3 deletions

View File

@@ -786,12 +786,15 @@ def authenticate(username, password, totp_token=None):
if config.get("totp_enabled"):
if not totp_token:
# First step: password OK, now request TOTP code (not a failure)
return False, None, True, "2FA code required"
# Verify TOTP token or backup code
success, message = verify_totp(username, totp_token, use_backup=len(totp_token) == 9) # Backup codes are formatted XXXX-XXXX
if not success:
return False, None, True, message
# TOTP code is wrong: return requires_totp=False so the caller
# logs it as a real authentication failure for Fail2Ban
return False, None, False, "Invalid 2FA code"
token = generate_token(username)
if token: