refact(password): Store permanent password as hashed verifier (#14619)

* refact(password): Store permanent password as hashed verifier

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(password): remove unused code

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(password): mobile, password dialog, width 500

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2026-03-26 14:49:54 +08:00
committed by GitHub
parent 285e29d2dc
commit 170516572e
64 changed files with 563 additions and 192 deletions

View File

@@ -609,19 +609,57 @@ pub fn update_temporary_password() {
}
#[inline]
pub fn permanent_password() -> String {
pub fn is_permanent_password_set() -> bool {
#[cfg(any(target_os = "android", target_os = "ios"))]
return Config::get_permanent_password();
return Config::has_permanent_password();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
return ipc::get_permanent_password();
{
let daemon_is_set = ipc::is_permanent_password_set();
// `daemon_is_set` is authoritative for the return value. Local storage is only used to
// decide whether we should attempt a sync to clear stale user-side state.
let local_storage_is_empty = if daemon_is_set {
true
} else {
let (storage, _) = Config::get_local_permanent_password_storage_and_salt();
storage.is_empty()
};
if daemon_is_set || !local_storage_is_empty {
allow_err!(ipc::sync_permanent_password_storage_from_daemon());
}
daemon_is_set
}
}
#[inline]
pub fn set_permanent_password(password: String) {
pub fn is_local_permanent_password_set() -> bool {
#[cfg(any(target_os = "android", target_os = "ios"))]
Config::set_permanent_password(&password);
return Config::has_local_permanent_password();
#[cfg(not(any(target_os = "android", target_os = "ios")))]
allow_err!(ipc::set_permanent_password(password));
{
allow_err!(ipc::sync_permanent_password_storage_from_daemon());
Config::has_local_permanent_password()
}
}
pub fn set_permanent_password_with_result(password: String) -> bool {
if config::Config::is_disable_change_permanent_password() {
return false;
}
#[cfg(any(target_os = "android", target_os = "ios"))]
{
config::Config::set_permanent_password(&password);
return true;
}
#[cfg(not(any(target_os = "android", target_os = "ios")))]
{
match crate::ipc::set_permanent_password_with_ack(password) {
Ok(ok) => ok,
Err(err) => {
log::warn!("Failed to set permanent password via IPC: {err}");
false
}
}
}
}
#[inline]