password max length prompt (#9248)

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2024-09-04 11:31:13 +08:00
committed by GitHub
parent 04c0f66ca9
commit 29e12b84a9
9 changed files with 47 additions and 16 deletions

View File

@@ -2282,6 +2282,10 @@ pub fn main_clear_trusted_devices() {
clear_trusted_devices()
}
pub fn main_max_encrypt_len() -> SyncReturn<usize> {
SyncReturn(max_encrypt_len())
}
pub fn session_request_new_display_init_msgs(session_id: SessionID, display: usize) {
if let Some(session) = sessions::get_session_by_session_id(&session_id) {
session.request_init_msgs(display);

View File

@@ -928,16 +928,23 @@ pub fn set_permanent_password(v: String) -> ResultType<()> {
pub fn set_unlock_pin(v: String, translate: bool) -> ResultType<()> {
let v = v.trim().to_owned();
let min_len = 4;
if !v.is_empty() && v.len() < min_len {
let err = if translate {
crate::lang::translate(
"Requires at least {".to_string() + &format!("{min_len}") + "} characters",
)
} else {
// Sometimes, translated can't show normally in command line
format!("Requires at least {} characters", min_len)
};
bail!(err);
let max_len = crate::ui_interface::max_encrypt_len();
let len = v.chars().count();
if !v.is_empty() {
if len < min_len {
let err = if translate {
crate::lang::translate(
"Requires at least {".to_string() + &format!("{min_len}") + "} characters",
)
} else {
// Sometimes, translated can't show normally in command line
format!("Requires at least {} characters", min_len)
};
bail!(err);
}
if len > max_len {
bail!("No more than {max_len} characters");
}
}
Config::set_unlock_pin(&v);
set_config("unlock-pin", v)

View File

@@ -1495,3 +1495,8 @@ pub fn clear_trusted_devices() {
#[cfg(not(any(target_os = "android", target_os = "ios")))]
ipc::clear_trusted_devices();
}
#[cfg(feature = "flutter")]
pub fn max_encrypt_len() -> usize {
hbb_common::config::ENCRYPT_MAX_LEN
}