Skip to main content

PasswordHasher

Trait PasswordHasher 

Source
pub trait PasswordHasher<H> {
    // Required method
    fn hash_password_with_salt(
        &self,
        password: &[u8],
        salt: &[u8],
    ) -> Result<H, Error>;

    // Provided method
    fn hash_password(&self, password: &[u8]) -> Result<H, Error> { ... }
}
Expand description

High-level trait for password hashing functions.

Generic around a password hash to be returned (typically phc::PasswordHash)

Required Methods§

Source

fn hash_password_with_salt( &self, password: &[u8], salt: &[u8], ) -> Result<H, Error>

Compute the hash H from the given password and salt, potentially using configuration stored in &self for the parameters, or otherwise the recommended defaults.

The salt should be unique per password. When in doubt, use PasswordHasher::hash_password which will choose the salt for you.

§Errors

These will vary by algorithm/implementation of this trait, but may be due to:

  • length restrictions on the password and/or salt
  • algorithm-specific internal error

Provided Methods§

Source

fn hash_password(&self, password: &[u8]) -> Result<H, Error>

Compute the hash H from the given password, potentially using configuration stored in &self for the parameters, or otherwise the recommended defaults.

A large random salt will be generated automatically.

§Errors

These will vary by algorithm/implementation of this trait, but may be due to:

  • length restrictions on the password
  • algorithm-specific internal error
  • RNG internal error

Implementors§

Source§

impl PasswordHasher<PasswordHash> for Argon2<'_>

Available on crate features alloc and password-hash only.