forked from mtusi2026/mtusi2026lab7
Implement lab 7 security and mTLS
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
"""Password KDF (Argon2id) — never store or compare plaintext passwords."""
|
||||
from argon2 import PasswordHasher
|
||||
from argon2.exceptions import VerifyMismatchError, InvalidHashError
|
||||
|
||||
# OWASP-aligned lab budget: memory_cost is KiB (19 MiB), t=2, p=1.
|
||||
_hasher = PasswordHasher(time_cost=2, memory_cost=19456, parallelism=1)
|
||||
|
||||
|
||||
def hash_password(password: str) -> str:
|
||||
return _hasher.hash(password)
|
||||
|
||||
|
||||
def verify_password(password: str, password_hash: str) -> bool:
|
||||
try:
|
||||
return _hasher.verify(password_hash, password)
|
||||
except (VerifyMismatchError, InvalidHashError):
|
||||
return False
|
||||
|
||||
def needs_rehash(password_hash: str) -> bool:
|
||||
return _hasher.check_needs_rehash(password_hash)
|
||||
Reference in New Issue
Block a user