refact(password): check invalid with 01 when set salt

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2026-05-20 18:26:18 +08:00
parent 0c218232d1
commit 9e00fa2762

View File

@@ -218,9 +218,12 @@ pub(super) fn password_is_empty_or_not_hashed(permanent_password_storage: &str)
if decode_permanent_password_h1_from_storage(permanent_password_storage).is_some() { if decode_permanent_password_h1_from_storage(permanent_password_storage).is_some() {
return false; return false;
} }
let (_, decrypted, should_store) = if permanent_password_storage.starts_with(PERMANENT_PASSWORD_ENC_VERSION) {
return false;
}
let (_, decrypted, looks_like_plaintext) =
decrypt_str_or_original(permanent_password_storage, PASSWORD_ENC_VERSION); decrypt_str_or_original(permanent_password_storage, PASSWORD_ENC_VERSION);
decrypted || should_store decrypted || looks_like_plaintext
} }
#[cfg(test)] #[cfg(test)]
@@ -424,4 +427,9 @@ mod tests {
assert!(!password_is_empty_or_not_hashed(&locked_storage)); assert!(!password_is_empty_or_not_hashed(&locked_storage));
} }
#[test]
fn test_password_is_empty_or_not_hashed_treats_invalid_01_storage_as_hashed() {
assert!(!password_is_empty_or_not_hashed("01not-a-valid-hash"));
}
} }