revert moving password hashing

This commit is contained in:
Felix Ableitner 2023-06-21 10:24:59 +02:00 committed by Nutomic
parent abb2efef19
commit 5d70a9fbe4
2 changed files with 7 additions and 4 deletions

View file

@ -1,7 +1,6 @@
use crate::PerformCrud;
use activitypub_federation::http_signatures::generate_actor_keypair;
use actix_web::web::Data;
use bcrypt::{hash, DEFAULT_COST};
use lemmy_api_common::{
context::LemmyContext,
person::{LoginResponse, Register},
@ -118,7 +117,7 @@ impl PerformCrud for Register {
let local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_person.id)
.email(data.email.as_deref().map(str::to_lowercase))
.password_encrypted(hash(&data.password, DEFAULT_COST)?)
.password_encrypted(data.password.to_string())
.show_nsfw(Some(data.show_nsfw))
.accepted_application(accepted_application)
.build();

View file

@ -56,7 +56,7 @@ impl LocalUser {
}
pub async fn is_email_taken(pool: &DbPool, email_: &str) -> Result<bool, Error> {
use diesel::dsl::*;
use diesel::dsl::{exists, select};
let conn = &mut get_conn(pool).await?;
select(exists(local_user.filter(email.eq(email_))))
.get_result(conn)
@ -81,9 +81,13 @@ impl Crud for LocalUser {
}
async fn create(pool: &DbPool, form: &Self::InsertForm) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let mut form_with_encrypted_password = form.clone();
let password_hash =
hash(&form.password_encrypted, DEFAULT_COST).expect("Couldn't hash password");
form_with_encrypted_password.password_encrypted = password_hash;
let local_user_ = insert_into(local_user)
.values(form)
.values(form_with_encrypted_password)
.get_result::<Self>(conn)
.await?;