Revert "Fix how 2FA codes are verified (#7429)" (#7436)

This reverts commit e0739709e7.
This commit is contained in:
RustDesk 2024-03-20 19:54:47 +08:00 committed by GitHub
parent e0739709e7
commit 8b9728b40b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -89,14 +89,16 @@ pub fn generate2fa() -> String {
pub fn verify2fa(code: String) -> bool { pub fn verify2fa(code: String) -> bool {
if let Some((info, totp)) = CURRENT_2FA.lock().unwrap().as_ref() { if let Some((info, totp)) = CURRENT_2FA.lock().unwrap().as_ref() {
let is_valid = totp.check_current(&code).unwrap_or(false); if let Ok(cur) = totp.generate_current() {
if is_valid { let res = code == cur;
if let Ok(v) = info.into_string() { if res {
#[cfg(not(any(target_os = "android", target_os = "ios")))] if let Ok(v) = info.into_string() {
crate::ipc::set_option("2fa", &v); #[cfg(not(any(target_os = "android", target_os = "ios")))]
#[cfg(any(target_os = "android", target_os = "ios"))] crate::ipc::set_option("2fa", &v);
Config::set_option("2fa".to_owned(), v); #[cfg(any(target_os = "android", target_os = "ios"))]
return is_valid; Config::set_option("2fa".to_owned(), v);
return res;
}
} }
} }
} }