iet-auth-basic
Bcrypt and Argon2 implementations of the password contracts, plus PasswordAuth.
iet-auth-basicimplementationPassword hashing and verificationHow to use it
iet-auth-basic turns a login plus password into a verified Principal using bcrypt (the BasicAuth default) or Argon2 (Argon2Auth). You supply a CredentialStore that maps a login to a subject, stored hash, and enabled flag; the crate owns hashing, bounded verification queues, and a same-cost dummy hash so unknown accounts cost the same as known ones. The result implements Authenticate<PasswordCredentials>, which login adapters such as iet-auth-basic-axum drive.
// crates/features/iet-auth-basic/tests/password.rs
use ;
use PasswordAuth;
// `Store: CredentialStore` resolves a login to subject + stored hash + enabled.
// `Verify: PasswordVerifier` checks a password against that hash.
// Build once at startup; the dummy hash uses the same algorithm and cost.
let auth = new;
for in
BasicAuth::configured(store, BcryptConfig::default())andArgon2Auth::configured(store, PasswordConfig)build the verifier and same-cost dummy hash for you.- Verification work is bounded; overload returns
password.busyorpassword.queue_timeoutrather than queueing without limit. - The returned
Principal.profileis alwaysNone; persona selection is a separate step (iet-auth-profiles).
How it works
authenticate looks the account up through the CredentialStore, verifies the password against the stored hash or the same-cost dummy hash, and only returns a Principal when the account is verified, enabled, and has a non-empty subject.
sequenceDiagram
participant C as "Caller"
participant P as "PasswordAuth"
participant S as "CredentialStore"
participant V as "PasswordVerifier"
C->>P: "authenticate PasswordCredentials"
P->>S: "account login"
S-->>P: "PasswordAccount or None"
alt "account present"
P->>V: "verify password stored hash"
else "unknown login"
P->>V: "verify password dummy hash"
end
V-->>P: "bool verified"
P-->>C: "Principal subject profile None"What it implements
- Implements
iet_auth::PasswordVerifierfromiet-auth. - Implements
iet_auth::PasswordHasherfromiet-auth. - Implements
iet_auth::Authenticate<PasswordCredentials>fromiet-auth.
What's inside
Modules
src/argon2.rssrc/bcrypt.rssrc/config.rssrc/lib.rssrc/password.rs
Public API
(root)
- type
BasicAuth— Default password authentication uses bcrypt. Select Argon2 explicitly via Argon2Auth. - type
Argon2Auth
argon2
- struct
Argon2Passwords pub fn new(config: config::PasswordConfig) -> AppResult<Self>
bcrypt
- struct
BcryptPasswords pub fn new(config: BcryptConfig) -> AppResult<Self>
config
- struct
BcryptConfig - struct
PasswordConfig
password
- struct
PasswordAuth pub fn new(store: S, verifier: V, dummy_hash: Secret<String>) -> Self— Dummy hash must use the same algorithm/cost as real account hashes.
Impl map
PasswordHasher for Argon2PasswordsPasswordVerifier for Argon2PasswordsPasswordHasher for BcryptPasswordsPasswordVerifier for BcryptPasswordsDefault for BcryptConfigAuthenticate<PasswordCredentials> for PasswordAuth<S, V>CredentialStore for StorePasswordVerifier for Verify
Depends on
External crates: argon2, bcrypt, rand_core, tokio, zeroize
Used by
- No other framework crate depends on it directly.
In this repository
examples/htmx-starterexamples/skills-only-appexamples/skills-only-app-task-tracker
Source: crates/features/iet-auth-basic