tts_labeling / utils /security.py
vargha's picture
sentry intergration
86cf81a
raw
history blame contribute delete
772 Bytes
import bcrypt
from utils.logger import Logger
log = Logger()
def hash_password(plain_password: str) -> str:
"""
Hash a plaintext password using bcrypt.
"""
# try:
hashed = bcrypt.hashpw(plain_password.encode("utf-8"), bcrypt.gensalt())
return hashed.decode("utf-8")
# except Exception as exc:
# log.error(f"Password hashing failed: {exc}")
# raise
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""
Verify a plaintext password against its bcrypt hash.
"""
# try:
return bcrypt.checkpw(
plain_password.encode("utf-8"), hashed_password.encode("utf-8")
)
# except Exception as exc:
# log.error(f"Password verification failed: {exc}")
# return False