Создание и первичная инициализация базы даных успешно завершена. Наполнение демо-данными прошло без ошибок

This commit is contained in:
2025-12-06 12:58:42 +03:00
parent f378de38da
commit f07843de5a
49 changed files with 734 additions and 353 deletions
+23 -9
View File
@@ -1,18 +1,32 @@
from passlib.context import CryptContext
from argon2 import PasswordHasher
from argon2.exceptions import (
VerifyMismatchError,
VerificationError,
InvalidHash,
)
from utils.loggers import logger
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
pwd_hasher = PasswordHasher(
time_cost=3,
memory_cost=65536,
parallelism=2,
)
def pwd_hash(pwd_plant: str) -> str:
return pwd_context.encrypt(pwd_plant)
def pwd_hash(pwd_plain: str) -> str:
pwd_plain = str(pwd_plain)
return pwd_hasher.hash(pwd_plain)
def pwd_verify(pwd_plant: str, pwd_hash: str) -> bool:
from utils.loggers import logger
def pwd_verify(pwd_plain: str, stored_hash: str) -> bool:
pwd_plain = str(pwd_plain)
try:
return pwd_context.verify(pwd_plant, pwd_hash)
except Exception as e:
logger.error(f"Password verification error: {str(e)}")
valid = pwd_hasher.verify(stored_hash, pwd_plain)
except (VerifyMismatchError, VerificationError, InvalidHash) as e:
logger.warning(f"Password verification failed: {e.__class__.__name__}")
return False
return valid