pub trait PasswordHasher<H> {
// Required method
fn hash_password_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> Result<H, Error>;
// Provided methods
fn hash_password(&self, password: &[u8]) -> Result<H, Error> { ... }
fn hash_password_with_rng<R>(
&self,
rng: &mut R,
password: &[u8],
) -> Result<H, Error>
where R: TryCryptoRng + ?Sized { ... }
}password-hash only.Expand description
High-level trait for password hashing functions.
Generic around a password hash to be returned (typically [phc::PasswordHash])
Required Methods§
Sourcefn hash_password_with_salt(
&self,
password: &[u8],
salt: &[u8],
) -> Result<H, Error>
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§
Sourcefn hash_password(&self, password: &[u8]) -> Result<H, Error>
Available on crate feature getrandom only.
fn hash_password(&self, password: &[u8]) -> Result<H, Error>
getrandom only.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
Sourcefn hash_password_with_rng<R>(
&self,
rng: &mut R,
password: &[u8],
) -> Result<H, Error>where
R: TryCryptoRng + ?Sized,
Available on crate feature rand_core only.
fn hash_password_with_rng<R>(
&self,
rng: &mut R,
password: &[u8],
) -> Result<H, Error>where
R: TryCryptoRng + ?Sized,
rand_core only.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 from the provided RNG.
§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
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl PasswordHasher<PasswordHash> for ShaCrypt
alloc only.