05/18 Enhanced codes and functionalities

This commit is contained in:
2026-05-18 11:38:28 -04:00
parent 22fff0660e
commit fc4145a78e
8 changed files with 197 additions and 13 deletions
+17 -1
View File
@@ -177,7 +177,23 @@ def require_jwt(f):
return decorated
# ── Recovery proof helpers (HMAC-nonce) ──────────────────────────────────────
# ── TOTP replay prevention ────────────────────────────────────────────────────
def is_totp_code_used(user_id: int, code: str) -> bool:
"""Return True if this TOTP code was already consumed for this user."""
from app.models.totp_used_code import TotpUsedCode
return TotpUsedCode.is_used(user_id, code)
def mark_totp_code_used(user_id: int, code: str) -> None:
"""
Record that this TOTP code was consumed so it cannot be replayed.
Caller must commit the session — the surrounding request handler does this.
"""
from app.models.totp_used_code import TotpUsedCode
TotpUsedCode.mark_used(user_id, code)
def generate_recovery_nonce() -> str:
"""