Skip to content

Commit

Permalink
Implement verification with try and main path
Browse files Browse the repository at this point in the history
  • Loading branch information
thespooler authored and HeroicKatora committed Apr 13, 2020
1 parent bc2440a commit e092eef
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions oxide-auth/src/primitives/registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use std::cmp;
use std::collections::HashMap;
use std::fmt;
use std::iter::{Extend, FromIterator};
use std::sync::{Arc, MutexGuard, RwLockWriteGuard};
use std::rc::Rc;
use std::sync::{Arc, MutexGuard, RwLockWriteGuard};

use argon2::{self, Config};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -312,17 +312,13 @@ impl PasswordPolicy for Argon2 {
fn check(&self, client_id: &str, passphrase: &[u8], stored: &[u8])
-> Result<(), RegistrarError>
{
let hash = String::from_utf8(stored.to_vec());
let valid = match hash {
Ok(hash) => argon2::verify_encoded_ext(&hash, passphrase, &[], client_id.as_bytes())
.map_err(|_| RegistrarError::PrimitiveError),
_ => Err(RegistrarError::PrimitiveError),
};

let hash = String::from_utf8(stored.to_vec())
.map_err(|_| RegistrarError::PrimitiveError)?;
let valid = argon2::verify_encoded_ext(&hash, passphrase, &[], client_id.as_bytes())
.map_err(|_| RegistrarError::PrimitiveError)?;
match valid {
Ok(true) => Ok(()),
Ok(false) => Err(RegistrarError::Unspecified),
Err(err) => Err(err),
true => Ok(()),
false => Err(RegistrarError::Unspecified),
}
}
}
Expand Down

0 comments on commit e092eef

Please sign in to comment.