mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-06 05:01:27 +03:00
password max length prompt (#9248)
Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
27
src/ipc.rs
27
src/ipc.rs
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user