1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Авторизация

This commit is contained in:
MoonTestUse1
2024-12-28 07:59:03 +06:00
parent 5e7ff99c10
commit 60c178e752

View File

@@ -1,11 +1,22 @@
from passlib.context import CryptContext
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
"""Authentication utilities"""
import bcrypt
def verify_password(plain_password: str, hashed_password: str) -> bool:
return pwd_context.verify(plain_password, hashed_password)
"""Verify a password against its hash"""
try:
return bcrypt.checkpw(
plain_password.encode('utf-8'),
hashed_password.encode('utf-8')
)
except Exception as e:
print(f"Password verification error: {e}")
return False
def get_password_hash(password: str) -> str:
return pwd_context.hash(password)
"""Generate password hash"""
try:
salt = bcrypt.gensalt()
return bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
except Exception as e:
print(f"Password hashing error: {e}")
raise