smart-chatbot-api / app /utils /api_key.py
GitHub Actions
Deploy from GitHub Actions (2026-03-15 12:10 UTC)
e5b256c
raw
history blame contribute delete
342 Bytes
import hashlib
import secrets
def generate_api_key() -> tuple[str, str]:
plaintext = secrets.token_urlsafe(32)
hashed = hashlib.sha256(plaintext.encode()).hexdigest()
return plaintext, hashed
def verify_api_key(plaintext: str, hashed_key: str) -> bool:
return hashlib.sha256(plaintext.encode()).hexdigest() == hashed_key