30 lines
602 B
Python
30 lines
602 B
Python
from argon2 import PasswordHasher
|
|
from argon2.exceptions import (
|
|
VerifyMismatchError,
|
|
VerificationError,
|
|
InvalidHash,
|
|
)
|
|
|
|
|
|
pwd_hasher = PasswordHasher(
|
|
time_cost=3,
|
|
memory_cost=65536,
|
|
parallelism=2,
|
|
)
|
|
|
|
|
|
def pwd_hash(pwd_plain: str) -> str:
|
|
pwd_plain = str(pwd_plain)
|
|
return pwd_hasher.hash(pwd_plain)
|
|
|
|
|
|
def pwd_verify(pwd_plain: str, stored_hash: str) -> bool:
|
|
pwd_plain = str(pwd_plain)
|
|
|
|
try:
|
|
valid = pwd_hasher.verify(stored_hash, pwd_plain)
|
|
except (VerifyMismatchError, VerificationError, InvalidHash) as e:
|
|
return False
|
|
|
|
return valid
|