Password helpers¶
litestar_auth.password
¶
Password hashing helpers built on top of pwdlib.
PasswordHelper(password_hash=None)
¶
Hash and verify passwords with Argon2 and bcrypt support.
Initialize the helper with Argon2 as primary and bcrypt as fallback.
Source code in litestar_auth/password.py
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.
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 stored hash is deprecated (e.g. bcrypt while Argon2 is preferred), pwdlib returns the new hash so the caller can persist it. When the hash is already current 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 |