Skip to main content

PasswordHasher

Trait PasswordHasher 

Source
pub trait PasswordHasher: Send + Sync {
    // Required methods
    fn algorithm(&self) -> &'static str;
    fn hash(&self, password: &str) -> Result<String, HasherError>;
    fn verify(&self, password: &str, stored: &str) -> Result<bool, HasherError>;
    fn identify(&self, stored: &str) -> bool;
}
Expand description

One hasher’s algorithm-specific interface. The trait is sync — hashing is CPU-bound and current implementations don’t need an executor.

Required Methods§

Source

fn algorithm(&self) -> &'static str

Algorithm identifier ("argon2id", "bcrypt", …). Used in telemetry and tests; not part of the wire format.

Source

fn hash(&self, password: &str) -> Result<String, HasherError>

Produce a stored-hash string for password.

Source

fn verify(&self, password: &str, stored: &str) -> Result<bool, HasherError>

Constant-time verify against a stored hash that THIS hasher produced. The chain calls this only after Self::identify returns true, so implementations can assume the format is theirs to parse.

Source

fn identify(&self, stored: &str) -> bool

true if stored was produced by this hasher’s algorithm. Implementations typically pattern-match a leading marker ("$argon2id$", "$2b$", "pbkdf2_sha256$", …).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl PasswordHasher for Argon2idHasher

Available on crate feature passwords only.