From 958f21a25402f29f51017c0fad6f9a340a8e0b8e Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 23 May 2025 10:26:30 +0800 Subject: [PATCH] fix: numeric one-time password on startup Signed-off-by: fufesou --- src/password_security.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/password_security.rs b/src/password_security.rs index ef5cf2b..739c85f 100644 --- a/src/password_security.rs +++ b/src/password_security.rs @@ -3,7 +3,7 @@ use sodiumoxide::base64; use std::sync::{Arc, RwLock}; lazy_static::lazy_static! { - pub static ref TEMPORARY_PASSWORD:Arc> = Arc::new(RwLock::new(Config::get_auto_password(temporary_password_length()))); + pub static ref TEMPORARY_PASSWORD:Arc> = 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