Buckets:

download
raw
825 Bytes
import hashlib
import hmac
import secrets
import string
from fief.settings import settings
def get_verify_code_hash(
code: str, *, secret: str = settings.secret.get_secret_value()
) -> str:
hash = hmac.new(secret.encode("utf-8"), code.encode("utf-8"), hashlib.sha256)
return hash.hexdigest()
def generate_verify_code(
*,
length: int = settings.email_verification_code_length,
secret: str = settings.secret.get_secret_value(),
) -> tuple[str, str]:
"""
Generate a verify code for email verification.
Returns both the actual value and its HMAC-SHA256 hash.
Only the latter shall be stored in database.
"""
code = "".join(
secrets.choice(string.ascii_uppercase + string.digits) for _ in range(length)
)
return code, get_verify_code_hash(code, secret=secret)

Xet Storage Details

Size:
825 Bytes
·
Xet hash:
79b0881bf35d0b86a4e0b39550573414bc2f0ddf8b85f08044fc5be4985534b7

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.