Optimized password hash errors
This commit is contained in:
@@ -33,10 +33,7 @@ pub async fn login<'a>(
|
||||
let db_user = DbUser::get_from_email(&state.pool, login_request.email).await?;
|
||||
|
||||
if let Some(pass) = db_user.password {
|
||||
match verify_password_hash(&login_request.password, &pass).await {
|
||||
Ok(_) => (),
|
||||
Err(_err) => return Err(crate::Error::Auth(crate::auth::AuthError::InvalidPassword)),
|
||||
};
|
||||
verify_password_hash(&login_request.password, &pass).await?;
|
||||
} else {
|
||||
return Err(AuthError::Unexpected.into());
|
||||
}
|
||||
@@ -71,10 +68,7 @@ pub async fn register(
|
||||
let member_ids: Vec<String> = members.into_iter().map(|m| m.member_id).collect();
|
||||
|
||||
// Hash password
|
||||
let password_hash = match generate_password_hash(auth_request.password).await {
|
||||
Ok(hash) => hash,
|
||||
Err(_err) => return Err(crate::Error::Auth(crate::auth::AuthError::InvalidToken)),
|
||||
};
|
||||
let password_hash = generate_password_hash(auth_request.password).await?;
|
||||
|
||||
let mut transaction = state.pool.begin().await?;
|
||||
|
||||
@@ -107,19 +101,13 @@ pub async fn change_password(
|
||||
) -> Result<(), crate::Error> {
|
||||
let (_, user) = get_user_from_header(&state.pool, &headers).await?;
|
||||
|
||||
let password_hash = match generate_password_hash(request.new_password).await {
|
||||
Ok(hash) => hash,
|
||||
Err(_err) => return Err(crate::Error::Auth(crate::auth::AuthError::InvalidPassword)),
|
||||
};
|
||||
|
||||
// Verify that password is correct
|
||||
let db_user: DbUser = user.into();
|
||||
|
||||
let old_password_hash = db_user.get_password(&state.pool).await?;
|
||||
verify_password_hash(&request.old_password, &old_password_hash).await?;
|
||||
|
||||
match verify_password_hash(&request.old_password, &old_password_hash).await {
|
||||
Ok(_) => (),
|
||||
Err(_err) => return Err(crate::Error::Auth(crate::auth::AuthError::InvalidPassword)),
|
||||
};
|
||||
// Generate password hash for new password
|
||||
let new_password_hash = generate_password_hash(request.new_password).await?;
|
||||
|
||||
let mut transaction = state.pool.begin().await?;
|
||||
|
||||
@@ -128,7 +116,7 @@ pub async fn change_password(
|
||||
&mut transaction,
|
||||
UpdateUser {
|
||||
email: None,
|
||||
password: Some(password_hash),
|
||||
password: Some(new_password_hash),
|
||||
admin: None,
|
||||
},
|
||||
)
|
||||
@@ -152,14 +140,10 @@ pub async fn change_email(
|
||||
) -> Result<(), crate::Error> {
|
||||
let (_, user) = get_user_from_header(&state.pool, &headers).await?;
|
||||
|
||||
// Verify that password is correct
|
||||
let db_user: DbUser = user.into();
|
||||
|
||||
let password_hash = db_user.get_password(&state.pool).await?;
|
||||
|
||||
match verify_password_hash(&request.password, &password_hash).await {
|
||||
Ok(_) => (),
|
||||
Err(_err) => return Err(crate::Error::Auth(crate::auth::AuthError::InvalidPassword)),
|
||||
};
|
||||
verify_password_hash(&request.password, &password_hash).await?;
|
||||
|
||||
let mut transaction = state.pool.begin().await?;
|
||||
|
||||
|
@@ -26,7 +26,3 @@ pub async fn get_current_members(
|
||||
|
||||
Ok(Json(members))
|
||||
}
|
||||
|
||||
pub async fn get_members(State(state): State<AppState>, body: String) -> Result<(), crate::Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -1,11 +1,6 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use axum::{
|
||||
extract::State,
|
||||
http::HeaderMap,
|
||||
Json,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use axum::{extract::State, http::HeaderMap, Json};
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::{
|
||||
@@ -143,7 +138,6 @@ pub struct MigrationStore {
|
||||
pub count: u32,
|
||||
}
|
||||
|
||||
|
||||
impl Row {
|
||||
fn from_csv_many(input: &str) -> Result<Vec<Self>, csv::Error> {
|
||||
let mut rdr = csv::ReaderBuilder::new()
|
||||
|
Reference in New Issue
Block a user