cargo fmt

This commit is contained in:
phoenix committed 2026-11-01 18:44:38 -05:00
1 parent 0127a45216
commit bc6b36defd
1 file changed
+7 -5
+7 -5
View File
@@ -12,7 +12,7 @@ use rand::distr::SampleString;
pub struct SaltString { pub struct SaltString {
pub raw: String, pub raw: String,
pub in_bytes: Vec<u8> pub in_bytes: Vec<u8>,
} }
impl SaltString { impl SaltString {
@@ -21,7 +21,7 @@ impl SaltString {
let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20); let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20);
let salt_string = SaltString { let salt_string = SaltString {
raw: (&s).to_string(), raw: (&s).to_string(),
in_bytes: s.into_bytes() in_bytes: s.into_bytes(),
}; };
Ok(salt_string) Ok(salt_string)
@@ -70,7 +70,9 @@ pub fn hash_password(
// parameters, salt, and the hash itself. // parameters, salt, and the hash itself.
// Ok(argon2.hash_password(password_bytes, salt)?.to_string()) // Ok(argon2.hash_password(password_bytes, salt)?.to_string())
// Ok(argon2.hash_password(password_bytes)?.to_string()) // Ok(argon2.hash_password(password_bytes)?.to_string())
Ok(argon2.hash_password_with_salt(password_bytes, &salt.in_bytes)?.to_string()) Ok(argon2
.hash_password_with_salt(password_bytes, &salt.in_bytes)?
.to_string())
} }
pub fn verify_password( pub fn verify_password(
@@ -87,9 +89,9 @@ pub fn verify_password(
// Verify the password against the parsed hash // Verify the password against the parsed hash
// This automatically uses the correct salt and parameters embedded in `parsed_hash` // This automatically uses the correct salt and parameters embedded in `parsed_hash`
match Argon2::default().verify_password(password_bytes, &parsed_hash) { match Argon2::default().verify_password(password_bytes, &parsed_hash) {
Ok(()) => Ok(true), // Passwords match Ok(()) => Ok(true), // Passwords match
Err(argon2::password_hash::Error::PasswordInvalid) => Ok(false), // Passwords don't match Err(argon2::password_hash::Error::PasswordInvalid) => Ok(false), // Passwords don't match
Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format) Err(e) => Err(e), // Some other error occurred (e.g., invalid hash format)
} }
} }