cleanup errors
This commit is contained in:
+6
-4
@@ -8,22 +8,24 @@ use argon2::{
|
||||
use async_trait::async_trait;
|
||||
use rand::RngCore;
|
||||
|
||||
use crate::domain::{DomainError, DomainResult};
|
||||
use crate::ports::{PasswordHasher, TokenGenerator};
|
||||
|
||||
pub struct Argon2PasswordHasher;
|
||||
|
||||
#[async_trait]
|
||||
impl PasswordHasher for Argon2PasswordHasher {
|
||||
fn hash(&self, password: &str) -> Result<String, String> {
|
||||
fn hash(&self, password: &str) -> DomainResult<String> {
|
||||
let salt = SaltString::generate(&mut OsRng);
|
||||
Argon2::default()
|
||||
.hash_password(password.as_bytes(), &salt)
|
||||
.map(|hash| hash.to_string())
|
||||
.map_err(|error| error.to_string())
|
||||
.map_err(|error| DomainError::Password(error.to_string()))
|
||||
}
|
||||
|
||||
fn verify(&self, password: &str, encoded_hash: &str) -> Result<bool, String> {
|
||||
let hash = PasswordHash::new(encoded_hash).map_err(|error| error.to_string())?;
|
||||
fn verify(&self, password: &str, encoded_hash: &str) -> DomainResult<bool> {
|
||||
let hash = PasswordHash::new(encoded_hash)
|
||||
.map_err(|error| DomainError::Password(error.to_string()))?;
|
||||
Ok(Argon2::default()
|
||||
.verify_password(password.as_bytes(), &hash)
|
||||
.is_ok())
|
||||
|
||||
Reference in New Issue
Block a user