Files
sshecret/packages/sshecret-backend/src/sshecret_backend/auth.py
2025-06-08 17:43:34 +02:00

19 lines
477 B
Python

"""Auth helpers."""
import bcrypt
def hash_token(token: str) -> str:
"""Hash a token."""
pwbytes = token.encode("utf-8")
salt = bcrypt.gensalt()
hashed_bytes = bcrypt.hashpw(password=pwbytes, salt=salt)
return hashed_bytes.decode()
def verify_token(token: str, stored_hash: str) -> bool:
"""Verify token."""
token_bytes = token.encode("utf-8")
stored_bytes = stored_hash.encode("utf-8")
return bcrypt.checkpw(token_bytes, stored_bytes)