From 21c6210869ed73ffe3e9552af78ec582b0ef4258 Mon Sep 17 00:00:00 2001 From: Thomas Stallinger Date: Tue, 4 Aug 2026 17:06:18 +0200 Subject: [PATCH] fix: password_hash aus DB als bytes statt str behandeln MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- app.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index 2ce171e..59e045b 100644 --- a/app.py +++ b/app.py @@ -99,7 +99,15 @@ def login_submit(request: Request, email: str = Form(...), password: str = Form( ) 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( request, "login.html", {"error": "E-Mail oder Passwort ist falsch."}, status_code=401 )