1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
Files
AdministrationItDepartmens/backend/app/utils/auth.py
2024-12-28 07:59:03 +06:00

22 lines
683 B
Python

"""Authentication utilities"""
import bcrypt
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""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:
"""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