Initial commit: Modernes Harry Potter Escape Quiz Portal (FastAPI & MariaDB)
This commit is contained in:
Executable
+16
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
import hashlib
|
||||
import secrets
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
salt = secrets.token_hex(16)
|
||||
key = hashlib.pbkdf2_hmac("sha256", password.encode("utf-8"), salt.encode("utf-8"), 100000)
|
||||
return f"{salt}${key.hex()}"
|
||||
|
||||
def verify_password(stored_password_hash: str, provided_password: str) -> bool:
|
||||
try:
|
||||
salt, key_hex = stored_password_hash.split("$", 1)
|
||||
new_key = hashlib.pbkdf2_hmac("sha256", provided_password.encode("utf-8"), salt.encode("utf-8"), 100000)
|
||||
return secrets.compare_digest(new_key.hex(), key_hex)
|
||||
except Exception:
|
||||
return False
|
||||
Reference in New Issue
Block a user