From 7a6cca4dac0546a2c0874b3eca66e2f856a7a8f0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 1 Nov 2026 17:17:17 -0500 Subject: [PATCH] Making some changes. Will fail tests --- src/hashing/mod.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/hashing/mod.rs b/src/hashing/mod.rs index 2c53f0b..46b1881 100644 --- a/src/hashing/mod.rs +++ b/src/hashing/mod.rs @@ -3,15 +3,34 @@ use argon2::{ PasswordVerifier, password_hash::{ PasswordHasher, - SaltString, - rand_core::OsRng, // Secure random number generator + // SaltString, + // rand_core::OsRng, // Secure random number generator }, }; +pub struct SaltString { + pub raw: String, + pub in_bytes: Vec +} + +impl SaltString { + pub fn generate() -> Result { + Err(argon2::Error::SaltTooLong) + } + + pub fn from_b64(s: &str) -> Result { + Err(argon2::password_hash::Error::SaltInvalid) + } + + pub fn to_string(&self) -> String { + self.raw.clone() + } +} + pub fn generate_salt() -> Result { // Generate a random salt // SaltString::generate uses OsRng internally for cryptographic security - Ok(SaltString::generate(&mut OsRng)) + SaltString::generate() } pub fn get_salt(s: &str) -> Result { @@ -31,7 +50,9 @@ pub fn hash_password( // Hash the password with the salt // The output is a PasswordHash string format that includes algorithm, version, // 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( @@ -49,7 +70,7 @@ pub fn verify_password( // This automatically uses the correct salt and parameters embedded in `parsed_hash` match Argon2::default().verify_password(password_bytes, &parsed_hash) { 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) } }