truncate passwords to 72 bytes to prevent bcrypt hashing errors

This commit is contained in:
CPTN Cosmo 2026-04-18 17:03:09 +02:00
parent bb7053b01e
commit 7dcda4b5ef
2 changed files with 5 additions and 3 deletions

View file

@ -37,10 +37,11 @@ app = FastAPI()
app.add_middleware(SessionMiddleware, secret_key=ENCRYPTION_KEY) app.add_middleware(SessionMiddleware, secret_key=ENCRYPTION_KEY)
def get_password_hash(password): def get_password_hash(password):
return pwd_context.hash(password) # bcrypt has a 72-byte limit
return pwd_context.hash(password[:72])
def verify_password(plain_password, hashed_password): def verify_password(plain_password, hashed_password):
return pwd_context.verify(plain_password, hashed_password) return pwd_context.verify(plain_password[:72], hashed_password)
def init_db(): def init_db():
conn = sqlite3.connect(DB_PATH) conn = sqlite3.connect(DB_PATH)

View file

@ -5,4 +5,5 @@ pyotp==2.9.0
httpx==0.25.1 httpx==0.25.1
pydantic==2.4.2 pydantic==2.4.2
itsdangerous==2.1.2 itsdangerous==2.1.2
passlib[bcrypt]==1.7.4 passlib==1.7.4
bcrypt==3.2.2