Aller au contenu

# Hashers

### `get_hasher()` `cached`

Source code in `api/hashers.py`

    33
    34
    35
    @functools.cache
    def get_hasher():
        return Sha512ApiKeyHasher()

### `generate_key()`

Generate a [key, hash] couple.

Source code in `api/hashers.py`

    38
    39
    40
    41
    42
    43
    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)