21 lines
671 B
Rust
21 lines
671 B
Rust
use super::hashing::HashedBytes;
|
|
use entity::master_pass;
|
|
use sea_orm::ActiveValue::Set;
|
|
|
|
pub trait MasterPassFromUnencryptedExt {
|
|
fn from_unencrypted(user_id: u64, password: &str) -> master_pass::ActiveModel;
|
|
}
|
|
|
|
impl MasterPassFromUnencryptedExt for master_pass::ActiveModel {
|
|
/// Hashes the password and creates an ActiveModel with all fields set to Set variant
|
|
#[inline]
|
|
fn from_unencrypted(user_id: u64, password: &str) -> Self {
|
|
let hash = HashedBytes::new(password.as_bytes());
|
|
Self {
|
|
user_id: Set(user_id),
|
|
password_hash: Set(hash.hash.to_vec()),
|
|
salt: Set(hash.salt.to_vec()),
|
|
}
|
|
}
|
|
}
|