diff options
| author | Dennis Fink | 2026-11-13 19:22:33 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-13 19:22:33 +0100 |
| commit | 5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232 (patch) | |
| tree | 04b442019424db67aa8ca23c5e652d12136f9fe7 /webmentions_ssg/auth.py | |
| parent | c421d269313d6623926954935a680fe4acb1dc86 (diff) | |
| download | webmentions-ssg-5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232.tar.gz webmentions-ssg-5c1eb15f00e20ece0a4ff8e7e1b4a5ab51e54232.zip | |
refactor(core): simplify login password verification
Replace the module-level dummy user with a lazily cached password hash
so unknown usernames still perform a password check without hashing
during every import.
Use one linear verification path for existing, missing, and empty
passwords.
Diffstat (limited to 'webmentions_ssg/auth.py')
| -rw-r--r-- | webmentions_ssg/auth.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/webmentions_ssg/auth.py b/webmentions_ssg/auth.py index 6d4fe95..edfc858 100644 --- a/webmentions_ssg/auth.py +++ b/webmentions_ssg/auth.py @@ -6,12 +6,14 @@ import hashlib import secrets +from functools import cache from hmac import compare_digest from urllib.parse import urlsplit from flask import request from flask_limiter.util import get_remote_address from flask_login import LoginManager +from werkzeug.security import generate_password_hash from .extensions import db from .models import User @@ -23,8 +25,11 @@ AUTH.login_view = "root.login" # pyright: ignore[reportAttributeAccessIssue] MIN_PASSWORD_LENGTH = 8 -DUMMY_USER = User(username=secrets.token_urlsafe()) -DUMMY_USER.password = secrets.token_urlsafe() + +@cache +def dummy_password_hash() -> str: + """Lazily generate a reusable hash for unknown login usernames.""" + return generate_password_hash(secrets.token_urlsafe()) def validate_password(password: str) -> None: |
