Skip to main content

hash_password_with_parameters

Function hash_password_with_parameters 

Source
pub fn hash_password_with_parameters(
    password: &[u8],
    params: DerivationParameters,
) -> Result<PasswordHash>
Expand description

Creates a PasswordHash using caller-supplied DerivationParameters.

The derivation algorithm (Argon2id or PBKDF2) is determined by what is encoded inside params. Obtain fresh parameters via crate::key_derivation::Argon2::parameters or crate::key_derivation::Pbkdf2::parameters.

ยงExample

use devolutions_crypto::password_hash::hash_password_with_parameters;
use devolutions_crypto::key_derivation::Argon2;
use devolutions_crypto::Argon2Parameters;

let mut params_cfg = Argon2Parameters::default();
params_cfg.memory = 131072; // 128 MiB
params_cfg.iterations = 4;
let params = Argon2::with_params(params_cfg).parameters();

let hash = hash_password_with_parameters(b"pa$$word", params).expect("should not fail");
assert!(hash.verify_password(b"pa$$word"));