diff options
Diffstat (limited to 'webmentions_ssg/models.py')
| -rw-r--r-- | webmentions_ssg/models.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/webmentions_ssg/models.py b/webmentions_ssg/models.py index 58f95bc..7cab879 100644 --- a/webmentions_ssg/models.py +++ b/webmentions_ssg/models.py @@ -9,6 +9,7 @@ from __future__ import annotations import uuid from datetime import UTC, datetime from enum import StrEnum +from hashlib import sha256 from typing import Never from flask_login import UserMixin @@ -77,6 +78,16 @@ class User(UserMixin, Base): """ self.password_hash = generate_password_hash(password) + def get_id(self) -> str: + """Bind the login session to the current stored password hash. + + Only a one-way fingerprint is placed in Flask's signed cookie, never + the password hash itself. Rehashing the password invalidates all + previously issued session identifiers without a schema change. + """ + fingerprint = sha256(self.password_hash.encode("utf-8")).hexdigest() + return f"{self.id}:{fingerprint}" + def check_password(self, password: str) -> bool: """ Check a plain-text password against the stored password hash. |
