Merge pull request #11 from TronoSfera/codex/fix-bcrypt-password-length-issue

Harden password hashing backend selection
This commit is contained in:
TronoSfera 2026-01-19 12:05:41 +03:00 committed by GitHub
commit 16266d3cc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -35,15 +35,19 @@ ALGORITHM = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "60"))
# Password hashing context
try:
def _build_password_context() -> CryptContext:
"""Create a password hashing context with a safe backend fallback."""
try:
passlib_bcrypt.bcrypt.set_backend("builtin")
passlib_bcrypt.bcrypt_sha256.set_backend("builtin")
except Exception:
# If the builtin backend is unavailable, fall back to the default backend.
pass
passlib_bcrypt.bcrypt_sha256.hash("passlib-backend-check")
return CryptContext(schemes=["bcrypt_sha256", "bcrypt"], deprecated="auto")
except Exception:
# bcrypt backends can fail with newer bcrypt releases; fall back to pbkdf2.
return CryptContext(schemes=["pbkdf2_sha256"], deprecated="auto")
pwd_context = CryptContext(schemes=["bcrypt_sha256", "bcrypt"], deprecated="auto")
pwd_context = _build_password_context()
def _normalize_bcrypt_password(password: str) -> str: