mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-07-10 01:22:48 +00:00
Add password to security keys
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
//!
|
||||
//! @author Pierre Hubert
|
||||
|
||||
use bcrypt::{DEFAULT_COST, hash_with_result};
|
||||
use webauthn_rs::proto::Credential;
|
||||
|
||||
use crate::constants::database_tables_names::ADMIN_KEYS_TABLE;
|
||||
@ -11,12 +12,13 @@ use crate::helpers::database;
|
||||
use crate::utils::date_utils::time;
|
||||
|
||||
/// Save a new key in the database
|
||||
pub fn add_key(id: AdminID, name: &str, key: Credential) -> Res<u64> {
|
||||
pub fn add_key(id: AdminID, name: &str, key: Credential, password: String) -> Res<u64> {
|
||||
database::InsertQuery::new(ADMIN_KEYS_TABLE)
|
||||
.add_admin_id("admin_id", id)
|
||||
.add_str("name", name)
|
||||
.add_u64("time_add", time())
|
||||
.add_str("credential", &serde_json::to_string(&key)?)
|
||||
.add_str("password", &hash_with_result(password, DEFAULT_COST)?.to_string())
|
||||
.insert_expect_result()
|
||||
}
|
||||
|
||||
@ -42,5 +44,6 @@ fn db_to_admin_key(row: &database::RowResult) -> Res<AdminKey> {
|
||||
name: row.get_str("name")?,
|
||||
time_add: row.get_u64("time_add")?,
|
||||
key: serde_json::from_str(&row.get_str("credential")?)?,
|
||||
password: row.get_optional_str("password")?,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user