fix: 管理员口令改为哈希并限制连续失败

This commit is contained in:
2026-11-16 02:35:15 +08:00
parent 77f80ad0e1
commit 0fbc3146d8
11 changed files with 209 additions and 26 deletions
+6 -1
View File
@@ -6,8 +6,10 @@
from __future__ import annotations
import hmac
import threading
from admin.passwords import is_hashed, verify_password
from euniv.crypto import decrypt_secret
@@ -32,10 +34,13 @@ class AdminIdentity:
cipher = self._password_cipher
if not cipher:
return False
if is_hashed(cipher):
return verify_password(cipher, password)
try:
return decrypt_secret(cipher) == password
stored = decrypt_secret(cipher).encode("utf-8")
except Exception:
return False
return hmac.compare_digest(stored, password.encode("utf-8"))
def username(self) -> str:
with self._lock: