fix: numeric one-time password on startup

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou 2025-05-23 10:26:30 +08:00
parent aa466d2ef4
commit 958f21a254

View File

@ -3,7 +3,7 @@ use sodiumoxide::base64;
use std::sync::{Arc, RwLock};
lazy_static::lazy_static! {
pub static ref TEMPORARY_PASSWORD:Arc<RwLock<String>> = Arc::new(RwLock::new(Config::get_auto_password(temporary_password_length())));
pub static ref TEMPORARY_PASSWORD:Arc<RwLock<String>> = Arc::new(RwLock::new(get_auto_password()));
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@ -20,14 +20,18 @@ pub enum ApproveMode {
Click,
}
fn get_auto_password() -> String {
let len = temporary_password_length();
if Config::get_bool_option(crate::config::keys::OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD) {
Config::get_auto_numeric_password(len)
} else {
Config::get_auto_password(len)
}
}
// Should only be called in server
pub fn update_temporary_password() {
*TEMPORARY_PASSWORD.write().unwrap() =
if Config::get_bool_option(crate::config::keys::OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD) {
Config::get_auto_numeric_password(temporary_password_length())
} else {
Config::get_auto_password(temporary_password_length())
};
*TEMPORARY_PASSWORD.write().unwrap() = get_auto_password();
}
// Should only be called in server