16 lines
344 B
Python
16 lines
344 B
Python
"""Opaque session-token generation and storage hashing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import secrets
|
|
|
|
|
|
def new_session_token() -> tuple[str, str]:
|
|
token = secrets.token_urlsafe(32)
|
|
return token, hash_token(token)
|
|
|
|
|
|
def hash_token(token: str) -> str:
|
|
return hashlib.sha256(token.encode("utf-8")).hexdigest()
|