Making some changes. Will fail tests
soaricarus_auth Build / Check (pull_request) Failing after 3m13s
soaricarus_auth Build / Test Suite (pull_request) Failing after 3m26s
soaricarus_auth Build / Rustfmt (pull_request) Failing after 20s
soaricarus_auth Build / Clippy (pull_request) Failing after 31s
soaricarus_auth Build / build (pull_request) Failing after 2m26s

This commit is contained in:
phoenix committed 2026-11-01 17:17:17 -05:00
1 parent 96f0d499fe
commit 7a6cca4dac
1 file changed
+26 -5
+26 -5
View File
@@ -3,15 +3,34 @@ use argon2::{
PasswordVerifier, PasswordVerifier,
password_hash::{ password_hash::{
PasswordHasher, PasswordHasher,
SaltString, // SaltString,
rand_core::OsRng, // Secure random number generator // rand_core::OsRng, // Secure random number generator
}, },
}; };
pub struct SaltString {
pub raw: String,
pub in_bytes: Vec<u8>
}
impl SaltString {
pub fn generate() -> Result<SaltString, argon2::Error> {
Err(argon2::Error::SaltTooLong)
}
pub fn from_b64(s: &str) -> Result<SaltString, argon2::password_hash::Error> {
Err(argon2::password_hash::Error::SaltInvalid)
}
pub fn to_string(&self) -> String {
self.raw.clone()
}
}
pub fn generate_salt() -> Result<SaltString, argon2::Error> { pub fn generate_salt() -> Result<SaltString, argon2::Error> {
// Generate a random salt // Generate a random salt
// SaltString::generate uses OsRng internally for cryptographic security // SaltString::generate uses OsRng internally for cryptographic security
Ok(SaltString::generate(&mut OsRng)) SaltString::generate()
} }
pub fn get_salt(s: &str) -> Result<SaltString, argon2::password_hash::Error> { pub fn get_salt(s: &str) -> Result<SaltString, argon2::password_hash::Error> {
@@ -31,7 +50,9 @@ pub fn hash_password(
// Hash the password with the salt // Hash the password with the salt
// The output is a PasswordHash string format that includes algorithm, version, // The output is a PasswordHash string format that includes algorithm, version,
// 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_with_salt(password_bytes, &salt.in_bytes)?.to_string())
} }
pub fn verify_password( pub fn verify_password(
@@ -49,7 +70,7 @@ pub fn verify_password(
// 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::Password) => 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)
} }
} }