Made verify_master_pass compute the hash in a blocking thread
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
use rand::{rngs::OsRng, RngCore};
|
||||
use scrypt::{scrypt, Params};
|
||||
use sea_orm::{entity::prelude::*, ActiveValue::Set, QuerySelect};
|
||||
use tokio::task::spawn_blocking;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "master_pass")]
|
||||
@ -43,7 +44,7 @@ impl ActiveModel {
|
||||
impl Entity {
|
||||
pub async fn verify_master_pass(
|
||||
user_id: u64,
|
||||
master_pass: &str,
|
||||
master_pass: String,
|
||||
db: &DatabaseConnection,
|
||||
) -> crate::Result<Option<bool>> {
|
||||
let model = match Self::find_by_id(user_id).one(db).await {
|
||||
@ -51,8 +52,10 @@ impl Entity {
|
||||
Ok(None) => return Ok(None),
|
||||
Err(err) => return Err(err.into()),
|
||||
};
|
||||
let password_hash = hash_password(master_pass.as_ref(), &model.salt)?;
|
||||
Ok(Some(password_hash == model.password_hash))
|
||||
let (hash, salt) = (model.password_hash, model.salt);
|
||||
let password_hash =
|
||||
spawn_blocking(move || hash_password(master_pass.as_bytes(), &salt)).await??;
|
||||
Ok(Some(password_hash == hash))
|
||||
}
|
||||
|
||||
/// Checks if the master password for the user exists
|
||||
|
Reference in New Issue
Block a user