mirror of
https://github.com/eduardogsilva/wireguard_webadmin.git
synced 2026-11-17 10:33:15 +01:00
Handle short TOTP secrets rejected by PyOTP 2.12 in auth-gateway and gatekeeper forms
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import logging
|
||||
|
||||
import pyotp
|
||||
|
||||
logger = logging.getLogger("uvicorn.error")
|
||||
|
||||
|
||||
def verify_totp(secret: str, token: str) -> bool:
|
||||
normalized_secret = secret.strip()
|
||||
normalized_token = token.strip().replace(" ", "")
|
||||
if not normalized_secret or not normalized_token:
|
||||
return False
|
||||
return pyotp.TOTP(normalized_secret).verify(normalized_token, valid_window=1)
|
||||
try:
|
||||
totp = pyotp.TOTP(normalized_secret)
|
||||
except ValueError as error:
|
||||
logger.warning("TOTP secret rejected (%s) — generate a new secret with at least 24 Base32 characters.", error)
|
||||
return False
|
||||
return totp.verify(normalized_token, valid_window=1)
|
||||
|
||||
Reference in New Issue
Block a user