23 lines
519 B
Python
23 lines
519 B
Python
import hashlib
|
|
import secrets
|
|
|
|
|
|
def hash_password(password: str) -> str:
|
|
import bcrypt
|
|
|
|
return bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt(rounds=12)).decode("utf-8")
|
|
|
|
|
|
def verify_password(password: str, password_hash: str) -> bool:
|
|
import bcrypt
|
|
|
|
return bcrypt.checkpw(password.encode("utf-8"), password_hash.encode("utf-8"))
|
|
|
|
|
|
def hash_secret(value: str) -> str:
|
|
return hashlib.sha256(value.encode("utf-8")).hexdigest()
|
|
|
|
|
|
def create_token() -> str:
|
|
return secrets.token_urlsafe(32)
|