feat(auth): add comprehensive debug logging for local login failures
Add detailed diagnostic log statements throughout the local authentication path to help identify why valid local user logins are failing. Changes: - app/auth.py: log received username, multi_user_enabled status, LocalUser DB lookup result, is_active status, password verification outcome, and the specific failure reason (empty_username / wrong_password / no_match) at every decision point. Also log form keys and Content-Type header on empty-username failures to detect Starlette body-consumption issues. - app/middleware/csrf.py: log Content-Type, form field names, and whether the CSRF token was present in _get_submitted_token() to reveal if the middleware is consuming form data before the endpoint can read it. - app/utils/local_auth.py: verify_password() now logs DEBUG on mismatch and WARNING (with exception type) on unexpected bcrypt errors instead of silently swallowing exceptions. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -32,8 +32,12 @@ def hash_password(plain: str) -> str:
|
||||
def verify_password(plain: str, hashed: str) -> bool:
|
||||
"""Return True when *plain* matches the stored bcrypt *hashed* string."""
|
||||
try:
|
||||
return bcrypt.checkpw(plain.encode("utf-8"), hashed.encode("utf-8"))
|
||||
except Exception:
|
||||
result = bcrypt.checkpw(plain.encode("utf-8"), hashed.encode("utf-8"))
|
||||
if not result:
|
||||
logger.debug("verify_password: mismatch password_provided=%s", bool(plain))
|
||||
return result
|
||||
except Exception as exc:
|
||||
logger.warning("verify_password: exception type=%s msg=%s", type(exc).__name__, exc)
|
||||
return False
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user