v0.0.1 first commit

This commit is contained in:
2026-07-29 17:36:22 +02:00
parent 49bb6815a0
commit 2eee55384e
28 changed files with 3902 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
import hashlib
import secrets
def hash_password(password: str, iterations: int = 200_000) -> str:
salt = secrets.token_bytes(16)
digest = hashlib.pbkdf2_hmac("sha256", password.encode("utf-8"), salt, iterations)
return f"pbkdf2_sha256${iterations}${salt.hex()}${digest.hex()}"
def verify_password(password: str, password_hash: str) -> bool:
try:
algorithm, rounds_raw, salt_hex, digest_hex = password_hash.split("$", 3)
if algorithm != "pbkdf2_sha256":
return False
rounds = int(rounds_raw)
salt = bytes.fromhex(salt_hex)
expected = bytes.fromhex(digest_hex)
except (ValueError, TypeError):
return False
candidate = hashlib.pbkdf2_hmac("sha256", password.encode("utf-8"), salt, rounds)
return secrets.compare_digest(candidate, expected)