fix: password_hash aus DB als bytes statt str behandeln

psycopg liefert die TEXT-Spalte password_hash beim SELECT als bytes
zurück, nicht als str wie beim create_user.py-Insert - bcrypt.checkpw()
schlug dadurch bei jedem Login-Versuch mit AttributeError fehl. Gefunden
beim ersten E2E-Login-Test auf anode.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Thomas Stallinger 2026-08-04 17:06:18 +02:00
parent c4825acd61
commit 21c6210869

10
app.py
View File

@ -99,7 +99,15 @@ def login_submit(request: Request, email: str = Form(...), password: str = Form(
) )
row = cur.fetchone() row = cur.fetchone()
if row is None or not bcrypt.checkpw(password.encode("utf-8"), row[2].encode("utf-8")): if row is None:
return templates.TemplateResponse(
request, "login.html", {"error": "E-Mail oder Passwort ist falsch."}, status_code=401
)
# psycopg liefert TEXT-Spalten hier als bytes zurück, nicht als str.
stored_hash = row[2] if isinstance(row[2], bytes) else row[2].encode("utf-8")
if not bcrypt.checkpw(password.encode("utf-8"), stored_hash):
return templates.TemplateResponse( return templates.TemplateResponse(
request, "login.html", {"error": "E-Mail oder Passwort ist falsch."}, status_code=401 request, "login.html", {"error": "E-Mail oder Passwort ist falsch."}, status_code=401
) )