Reduce the memory used by argon2 (less secure)
This commit is contained in:
parent
de19c3fa5d
commit
38c286e860
1 changed files with 16 additions and 2 deletions
|
|
@ -5,9 +5,23 @@ use argon2::{
|
|||
Argon2,
|
||||
};
|
||||
|
||||
fn get_argon2<'k>() -> Argon2<'k> {
|
||||
Argon2::new(
|
||||
argon2::Algorithm::Argon2id,
|
||||
argon2::Version::V0x13,
|
||||
argon2::Params::new(
|
||||
4_096, // 4 MB. The code run on raspberry pi zero, the default memory is too high.
|
||||
4, // Number of iteration.
|
||||
2, // Degree of parallelism.
|
||||
None,
|
||||
)
|
||||
.unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn hash(password: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
let argon2 = Argon2::default();
|
||||
let argon2 = get_argon2();
|
||||
argon2
|
||||
.hash_password(password.as_bytes(), &salt)
|
||||
.map(|h| h.to_string())
|
||||
|
|
@ -18,7 +32,7 @@ pub fn verify_password(
|
|||
password: &str,
|
||||
hashed_password: &str,
|
||||
) -> Result<bool, Box<dyn std::error::Error>> {
|
||||
let argon2 = Argon2::default();
|
||||
let argon2 = get_argon2();
|
||||
let parsed_hash = PasswordHash::new(hashed_password)?;
|
||||
Ok(argon2
|
||||
.verify_password(password.as_bytes(), &parsed_hash)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue