feat: complete Epic 1 production foundation
This commit is contained in:
1 parent
767428436d
commit
182bde8ac0
298 files changed
+35711
-5291
No files matched your search
@@ -2,8 +2,9 @@
|
||||
use argon2::{Algorithm, Params, Version};
|
||||
use argon2::{
|
||||
Argon2,
|
||||
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString, rand_core::OsRng},
|
||||
password_hash::{PasswordHash, PasswordHasher, PasswordVerifier, SaltString},
|
||||
};
|
||||
use rand::RngExt;
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum HashPasswordError {
|
||||
@@ -14,7 +15,10 @@ pub enum HashPasswordError {
|
||||
}
|
||||
|
||||
pub fn hash_password(password: &str, pepper: &str) -> Result<String, HashPasswordError> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
let mut salt_bytes = [0u8; 16];
|
||||
rand::rng().fill(&mut salt_bytes);
|
||||
let salt = SaltString::encode_b64(&salt_bytes)
|
||||
.map_err(|error| HashPasswordError::Hash(error.to_string()))?;
|
||||
let password = format!("{password}{pepper}");
|
||||
password_hasher()?
|
||||
.hash_password(password.as_bytes(), &salt)
|
||||
|
||||
Reference in new issue
Block a user