new: pdm package manager (python) new: workspace for three subprojects new: dream2nix module for packaging new: postgresql and redis images more: and more
17 lines
495 B
Python
17 lines
495 B
Python
from typing import Literal
|
|
|
|
import bcrypt
|
|
|
|
|
|
def hash_password(password: str, algo: Literal["bcrypt"] = "bcrypt") -> str:
|
|
if algo == "bcrypt":
|
|
return bcrypt.hashpw(password.encode(), bcrypt.gensalt()).decode()
|
|
else:
|
|
raise NotImplemented(algo)
|
|
|
|
def validate_password(password: str, hash: str, algo: Literal["bcrypt"] = "bcrypt") -> bool:
|
|
if algo == "bcrypt":
|
|
return bcrypt.checkpw(password.encode(), hash.encode())
|
|
else:
|
|
raise NotImplemented(algo)
|