Backend: passlib entfernt, bcrypt direkt nutzen (Fix fuer Startup-Crash/Restart-Loop)

passlib 1.7.4 vertraegt sich schlecht mit bcrypt 4.x und kann beim Hashen des
Admin-Passworts im Startup (ensure_first_admin) crashen -> Backend-Container in
Restart-Loop -> 502 in der Web-UI. hash_password/verify_password nutzen jetzt
bcrypt direkt (mit 72-Byte-Grenze). passlib aus requirements entfernt.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-22 09:39:36 +02:00
parent f0f652ddbe
commit 022a6d5ea8
2 changed files with 10 additions and 5 deletions

View File

@@ -1,21 +1,27 @@
from datetime import datetime, timedelta, timezone
import bcrypt
from jose import JWTError, jwt
from passlib.context import CryptContext
from .config import get_settings
settings = get_settings()
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# bcrypt akzeptiert maximal 72 Bytes längere Passwörter werden abgeschnitten.
_BCRYPT_MAX_BYTES = 72
def hash_password(password: str) -> str:
return pwd_context.hash(password)
pw = password.encode("utf-8")[:_BCRYPT_MAX_BYTES]
return bcrypt.hashpw(pw, bcrypt.gensalt()).decode("utf-8")
def verify_password(password: str, password_hash: str) -> bool:
return pwd_context.verify(password, password_hash)
try:
pw = password.encode("utf-8")[:_BCRYPT_MAX_BYTES]
return bcrypt.checkpw(pw, password_hash.encode("utf-8"))
except (ValueError, TypeError):
return False
def create_access_token(subject: str, role: str) -> str:

View File

@@ -5,7 +5,6 @@ psycopg2-binary==2.9.10
pydantic==2.10.4
pydantic-settings==2.7.1
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
bcrypt==4.2.1
httpx==0.28.1
python-dateutil==2.9.0.post0