Files
mtusi2026lab5/src/passwords.py
T

23 lines
564 B
Python

"""Argon2id. Одновременно считаются не более двух хешей."""
from threading import Semaphore
from argon2 import PasswordHasher
from argon2.exceptions import VerificationError
hasher = PasswordHasher(time_cost=2, memory_cost=19456, parallelism=1)
slots = Semaphore(2)
def hash_password(password):
with slots:
return hasher.hash(password)
def matches(encoded, password):
with slots:
try:
return hasher.verify(encoded, password)
except VerificationError:
return False