Password helpers¶
The plugin-owned password wiring now lives in
Configuration. PasswordHelper is the
hashing boundary itself. Use PasswordHelper.from_defaults() when you want the library's default
pwdlib configuration: Argon2 only for new hashes and verification. Unsupported stored password
hashes fail closed under that default, so rotate or reset those credentials before rollout. Use
PasswordHelper(password_hash=...) only for deliberate application-owned custom pwdlib
composition.
For plugin-managed apps that also hash or verify passwords in domain services, CLI tasks, or data
migrations, call config.resolve_password_helper() once after constructing
LitestarAuthConfig(...). That method returns the explicit
user_manager_security.password_helper when you already supplied one; otherwise it memoizes
PasswordHelper.from_defaults() on the config, and the plugin injects that same memoized helper
into every request-scoped manager so the plugin and app-owned code reuse the same instance.
litestar_auth.password
¶
Password hashing helpers built on top of pwdlib.
PasswordHelper(password_hash=None)
¶
Hash and verify passwords with a configurable pwdlib pipeline.
Initialize the helper with the provided pwdlib hash pipeline.
Source code in litestar_auth/password.py
from_defaults()
classmethod
¶
Return a helper configured with the library's default Argon2-only policy.
hash(password)
¶
verify(password, hashed)
¶
Verify a password against a stored hash.
pwdlib delegates verification to the selected hasher, which performs constant-time comparison for password checks. Treat unsupported or malformed hashes, along with hasher-level validation failures, as authentication failures instead of bubbling an exception into the login flow.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in litestar_auth/password.py
verify_and_update(password, hashed)
¶
Verify a password and return an updated hash when the stored one is deprecated.
Uses pwdlib's verify_and_update: when the configured pipeline marks the
stored hash as deprecated, pwdlib returns the new hash so the caller can
persist it. When the hash is already current, unsupported, malformed, or the
password is wrong, the second element is None.
Returns:
| Type | Description |
|---|---|
bool
|
A pair (verified, new_hash). When |
str | None
|
None, the caller should update the stored hash to |