перенос 4 лабы и реализация 5

This commit is contained in:
Ванек
2026-11-12 18:53:34 +03:00
parent 276dbdad8a
commit eca7c0f763
83 changed files with 13505 additions and 57 deletions
+22
View File
@@ -0,0 +1,22 @@
"""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