Aller au contenu

Hashers

get_hasher() cached

Source code in api/hashers.py
@functools.cache
def get_hasher():
    return Sha512ApiKeyHasher()

generate_key()

Generate a [key, hash] couple.

Source code in api/hashers.py
def generate_key() -> tuple[str, str]:
    """Generate a [key, hash] couple."""
    # this will result in key with a length of 72
    key = str(secrets.token_urlsafe(54))
    hasher = get_hasher()
    return key, hasher.encode(key)