from passlib.context import CryptContext
import logging
logger = logging.getLogger(__name__)
# Configure password hashing
pwd_context = CryptContext(
schemes=["bcrypt"],
deprecated="auto",
bcrypt__rounds=12
)
def get_password_hash(password: str) -> str:
"""Hash a password"""
try:
return pwd_context.hash(password)
except Exception as e:
logger.error(f"Error hashing password: {str(e)}")
raise
def verify_password(plain_password: str, hashed_password: str) -> bool:
"""Verify a password against its hash"""
try:
return pwd_context.verify(plain_password, hashed_password)
except Exception as e:
logger.error(f"Error verifying password: {str(e)}")
return False