Merge pull request #177 from fufesou/feat/numeric_one_time_password

feat: numeric one-time password
This commit is contained in:
RustDesk 2025-05-22 21:57:04 +08:00 committed by GitHub
commit aa466d2ef4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View File

@ -93,6 +93,8 @@ lazy_static::lazy_static! {
]);
}
const NUM_CHARS: &[char] = &['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
const CHARS: &[char] = &[
'2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
@ -883,9 +885,17 @@ impl Config {
}
pub fn get_auto_password(length: usize) -> String {
Self::get_auto_password_with_chars(length, CHARS)
}
pub fn get_auto_numeric_password(length: usize) -> String {
Self::get_auto_password_with_chars(length, NUM_CHARS)
}
fn get_auto_password_with_chars(length: usize, chars: &[char]) -> String {
let mut rng = rand::thread_rng();
(0..length)
.map(|_| CHARS[rng.gen::<usize>() % CHARS.len()])
.map(|_| chars[rng.gen::<usize>() % chars.len()])
.collect()
}
@ -2419,6 +2429,7 @@ pub mod keys {
pub const OPTION_ENABLE_RECORD_SESSION: &str = "enable-record-session";
pub const OPTION_ENABLE_BLOCK_INPUT: &str = "enable-block-input";
pub const OPTION_ALLOW_REMOTE_CONFIG_MODIFICATION: &str = "allow-remote-config-modification";
pub const OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD: &str = "allow-numeric-one-time-password";
pub const OPTION_ENABLE_LAN_DISCOVERY: &str = "enable-lan-discovery";
pub const OPTION_DIRECT_SERVER: &str = "direct-server";
pub const OPTION_DIRECT_ACCESS_PORT: &str = "direct-access-port";
@ -2583,6 +2594,7 @@ pub mod keys {
OPTION_ENABLE_RECORD_SESSION,
OPTION_ENABLE_BLOCK_INPUT,
OPTION_ALLOW_REMOTE_CONFIG_MODIFICATION,
OPTION_ALLOW_NUMERNIC_ONE_TIME_PASSWORD,
OPTION_ENABLE_LAN_DISCOVERY,
OPTION_DIRECT_SERVER,
OPTION_DIRECT_ACCESS_PORT,

View File

@ -22,7 +22,12 @@ pub enum ApproveMode {
// Should only be called in server
pub fn update_temporary_password() {
*TEMPORARY_PASSWORD.write().unwrap() = Config::get_auto_password(temporary_password_length());
*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())
};
}
// Should only be called in server