Spaces:
Sleeping
Sleeping
Update src/utils/security.py
Browse files15 unmodified lines16171819202122232425262715 unmodified lines_FALLBACK_ACCESS_TOKEN_EXPIRE_DAYS = 7# Password hashing contextpwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")def hash_password(password: str) -> str:"""Hash a password using bcrypt."""try:return pwd_context.hash(password)except Exception as e:logger.error(f"Error hashing password: {str(e)}")15 unmodified lines16171819202122232425262728293031323334353615 unmodified lines_FALLBACK_ACCESS_TOKEN_EXPIRE_DAYS = 7# Password hashing context# Handle bcrypt backend issues by specifying a fallbacktry:pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")except Exception as e:logger.warning(f"Failed to initialize bcrypt context: {e}, using plaintext (NOT FOR PRODUCTION)")pwd_context = CryptContext(schemes=["plaintext"], deprecated="auto")def hash_password(password: str) -> str:"""Hash a password using bcrypt."""try:# Truncate password to 72 bytes to avoid bcrypt limitationif len(password.encode('utf-8')) > 72:logger.warning("Password exceeds 72 bytes, truncating")password = password.encode('utf-8')[:72].decode('utf-8', errors='ignore')return pwd_context.hash(password)except Exception as e:logger.error(f"Error hashing password: {str(e)}")
src/utils/security.py+10-1