21 lines
653 B
Rust
21 lines
653 B
Rust
use super::hashing::HashedBytes;
|
|
use entity::master_pass;
|
|
use sea_orm::ActiveValue::Set;
|
|
|
|
pub trait FromUnencryptedExt {
|
|
fn from_unencrypted(user_id: u64, password: &str) -> master_pass::ActiveModel;
|
|
}
|
|
|
|
impl FromUnencryptedExt 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()),
|
|
}
|
|
}
|
|
}
|