diff --git a/src/entity/master_pass.rs b/src/entity/master_pass.rs index e08c826..7f9328c 100644 --- a/src/entity/master_pass.rs +++ b/src/entity/master_pass.rs @@ -20,9 +20,9 @@ impl ActiveModelBehavior for ActiveModel {} /// Hashes the password with Scrypt with the given salt #[inline] -fn hash_password(password: &[u8], salt: &[u8]) -> crate::Result> { +fn hash_password(password: &[u8], salt: &[u8]) -> crate::Result<[u8; 64]> { let params = Params::new(14, Params::RECOMMENDED_R, Params::RECOMMENDED_P, 64)?; - let mut password_hash = vec![0; 64]; + let mut password_hash = [0; 64]; scrypt(password, salt, ¶ms, &mut password_hash)?; Ok(password_hash) } @@ -31,7 +31,7 @@ impl Model { /// Checks that the given password hash matches the one of the model pub fn verify(&self, password: &str) -> crate::Result { let hashed = hash_password(password.as_bytes(), &self.salt)?; - Ok(hashed == self.password_hash) + Ok(hashed == self.password_hash.as_slice()) } } @@ -41,7 +41,7 @@ impl ActiveModel { pub fn from_unencrypted(user_id: u64, password: &str) -> crate::Result { let mut salt = vec![0; 64]; OsRng.fill_bytes(&mut salt); - let password_hash = Set(hash_password(password.as_ref(), &salt)?); + let password_hash = Set(hash_password(password.as_bytes(), &salt)?.to_vec()); Ok(Self { user_id: Set(user_id), salt: Set(salt),