16 lines
456 B
Python
16 lines
456 B
Python
from typing import Optional
|
|
from passlib.context import CryptContext
|
|
import hashlib
|
|
|
|
pwd_context = CryptContext(schemes=["argon2"], deprecated="auto")
|
|
|
|
def hash_password(pwd: str) -> str:
|
|
return pwd_context.hash(pwd)
|
|
|
|
def verify_password(pwd: str, hash: str) -> bool:
|
|
return pwd_context.verify(pwd, hash)
|
|
|
|
def hash_token(token: Optional[str]) -> str:
|
|
if not token:
|
|
return ""
|
|
return hashlib.sha256(token.encode("utf-8")).hexdigest()
|