feat: argon2-passwörter, benutzer-service und lc-admin-cli
- Passwort-Hashing mit argon2id, Dummy-Prüfung für unbekannte Benutzer - Benutzernamen werden normalisiert und validiert, Passwörter ab 12 Zeichen - lc-admin create-admin|create-user|reset-password, verweigert root Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d4cf8bdddd
commit
04161bcf1d
6 files changed
+273
-1
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import InvalidHashError, VerificationError
|
||||
|
||||
_hasher = PasswordHasher()
|
||||
|
||||
# Verified against when the user does not exist, so failed logins take the same time
|
||||
_DUMMY_HASH = _hasher.hash(secrets.token_urlsafe(16))
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return _hasher.hash(password)
|
||||
|
||||
|
||||
def verify_password(password_hash: str | None, password: str) -> bool:
|
||||
"""Check a password; pass None for unknown users to keep the timing identical."""
|
||||
try:
|
||||
_hasher.verify(password_hash or _DUMMY_HASH, password)
|
||||
except (VerificationError, InvalidHashError):
|
||||
return False
|
||||
return password_hash is not None
|
||||
|
||||
|
||||
def password_needs_rehash(password_hash: str) -> bool:
|
||||
return _hasher.check_needs_rehash(password_hash)
|
||||
|
||||
|
||||
def new_token() -> str:
|
||||
return secrets.token_urlsafe(32)
|
||||
|
||||
|
||||
def hash_token(token: str) -> str:
|
||||
return hashlib.sha256(token.encode()).hexdigest()
|
||||
Reference in new issue
Block a user