Making some changes

This commit is contained in:
phoenix committed 2026-11-01 18:44:12 -05:00
1 parent a729d2f5dd
commit 0127a45216
1 file changed
+20 -2
+20 -2
View File
@@ -8,6 +8,8 @@ use argon2::{
}, },
}; };
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>
@@ -15,11 +17,27 @@ pub struct SaltString {
impl SaltString { impl SaltString {
pub fn generate() -> Result<SaltString, argon2::Error> { pub fn generate() -> Result<SaltString, argon2::Error> {
Err(argon2::Error::SaltTooLong) let mut rng = rand::rng();
let s = rand::distr::Alphanumeric.sample_string(&mut rng, 20);
let salt_string = SaltString {
raw: (&s).to_string(),
in_bytes: s.into_bytes()
};
Ok(salt_string)
// Err(argon2::Error::SaltTooLong)
} }
pub fn from_b64(s: &str) -> Result<SaltString, argon2::password_hash::Error> { pub fn from_b64(s: &str) -> Result<SaltString, argon2::password_hash::Error> {
Err(argon2::password_hash::Error::SaltInvalid) let salt_string = SaltString {
raw: (&s).to_string(),
in_bytes: s.to_string().into_bytes(),
};
Ok(salt_string)
// Err(argon2::password_hash::Error::SaltInvalid)
} }
pub fn to_string(&self) -> String { pub fn to_string(&self) -> String {