fix: 管理员口令改为哈希并限制连续失败
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user