Files
prod-end-2026/backend/app/utils/hashing.py
T
2026-03-17 18:32:44 +03:00

17 lines
471 B
Python

import bcrypt
def hash_password(password: str) -> str:
pwd_bytes = password.encode("utf-8")
salt = bcrypt.gensalt()
return bcrypt.hashpw(pwd_bytes, salt).decode("utf-8")
def verify_password(plain_password: str, hashed_password: str) -> bool:
try:
pwd_bytes = plain_password.encode("utf-8")
hashed_bytes = hashed_password.encode("utf-8")
return bcrypt.checkpw(pwd_bytes, hashed_bytes)
except Exception:
return False