forked from mtusi2026/mtusi2026lab2
reworked
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import InvalidHashError, VerifyMismatchError
|
||||
|
||||
hasher = PasswordHasher(time_cost=2, memory_cost=8192, parallelism=1)
|
||||
_dummy = None
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return hasher.hash(password)
|
||||
|
||||
|
||||
def dummy_hash() -> str:
|
||||
global _dummy
|
||||
if _dummy is None:
|
||||
_dummy = hash_password("timing-dummy-password")
|
||||
return _dummy
|
||||
|
||||
|
||||
def verify_password(password_hash: str, password: str) -> bool:
|
||||
try:
|
||||
return hasher.verify(password_hash, password)
|
||||
except (VerifyMismatchError, InvalidHashError, TypeError, ValueError):
|
||||
return False
|
||||
Reference in New Issue
Block a user