From 8b9728b40bbfa83df0e8b8394a92d9ce935a5c4a Mon Sep 17 00:00:00 2001 From: RustDesk <71636191+rustdesk@users.noreply.github.com> Date: Wed, 20 Mar 2024 19:54:47 +0800 Subject: [PATCH] Revert "Fix how 2FA codes are verified (#7429)" (#7436) This reverts commit e0739709e736eec905d74cb7d6114deb8def9b2d. --- src/auth_2fa.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/auth_2fa.rs b/src/auth_2fa.rs index accc3b34d..bfbecd4e9 100644 --- a/src/auth_2fa.rs +++ b/src/auth_2fa.rs @@ -89,14 +89,16 @@ pub fn generate2fa() -> String { pub fn verify2fa(code: String) -> bool { if let Some((info, totp)) = CURRENT_2FA.lock().unwrap().as_ref() { - let is_valid = totp.check_current(&code).unwrap_or(false); - if is_valid { - if let Ok(v) = info.into_string() { - #[cfg(not(any(target_os = "android", target_os = "ios")))] - crate::ipc::set_option("2fa", &v); - #[cfg(any(target_os = "android", target_os = "ios"))] - Config::set_option("2fa".to_owned(), v); - return is_valid; + if let Ok(cur) = totp.generate_current() { + let res = code == cur; + if res { + if let Ok(v) = info.into_string() { + #[cfg(not(any(target_os = "android", target_os = "ios")))] + crate::ipc::set_option("2fa", &v); + #[cfg(any(target_os = "android", target_os = "ios"))] + Config::set_option("2fa".to_owned(), v); + return res; + } } } }