Skip to content
Edit this page

Hashing

Titancore hashes passwords through argon2-cffi and bcrypt. New hashes default to Argon2id. Both algorithms generate a fresh random salt for every password. The Hash facade runs hashing and verification in worker threads.

Register the provider after configuration bootstrap.

from titancore import Application
from titancore.facades import Hash
from titancore.foundation.bootstrap import default_bootstrappers
from titancore.hashing import HashingServiceProvider

app = Application()
app.bootstrap_with(default_bootstrappers())
app.register(HashingServiceProvider())

async with app:
    encoded = await Hash.make("example password")
    assert await Hash.check("example password", encoded)
    if await Hash.needs_rehash(encoded):
        encoded = await Hash.make("example password")

The application reads the hashing section of YAML configuration.

driver: argon2id
rounds: 12

Save these values in config/hashing.yaml. The rounds setting controls bcrypt's logarithmic work factor. Argon2id uses the dependency's recommended defaults. Select a named algorithm with await Hash.driver("bcrypt"). The returned hasher exposes synchronous make, check, and needs_rehash methods. Use the facade's asynchronous methods in request handlers.

Verification accepts either supported encoded format, allowing an application to migrate stored hashes after a successful login. Invalid hashes and incorrect passwords return false. needs_rehash returns true when the algorithm or configured work factor differs. bcrypt rejects passwords longer than 72 UTF-8 bytes.

The Hasher and HashManager contracts live in titancore.contracts.hashing. The application resolves the same manager through its concrete type, contract, and "hash" key.