preset password warning

This commit is contained in:
rustdesk 2024-03-16 11:52:30 +08:00
parent ccf5b0ef53
commit fe0de47805
5 changed files with 59 additions and 1 deletions

View File

@ -75,11 +75,50 @@ class _DesktopHomePageState extends State<DesktopHomePage>
);
}
Widget buildPresetPasswordWarning() {
return FutureBuilder<bool>(
future: bind.isPresetPassword(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator(); // Show a loading spinner while waiting for the Future to complete
} else if (snapshot.hasError) {
return Text(
'Error: ${snapshot.error}'); // Show an error message if the Future completed with an error
} else if (snapshot.hasData && snapshot.data == true) {
return Container(
color: Colors.yellow,
child: Column(
children: [
Align(
child: Text(
translate("Security Alert"),
style: TextStyle(
color: Colors.red,
fontSize: 20,
fontWeight: FontWeight.bold,
),
)).paddingOnly(bottom: 8),
Text(
translate("preset_password_warning"),
style: TextStyle(color: Colors.red),
)
],
).paddingAll(8),
); // Show a warning message if the Future completed with true
} else {
return SizedBox
.shrink(); // Show nothing if the Future completed with false or null
}
},
);
}
Widget buildLeftPane(BuildContext context) {
final isIncomingOnly = bind.isIncomingOnly();
final isOutgoingOnly = bind.isOutgoingOnly();
final logo = loadLogo();
final children = <Widget>[
if (!isOutgoingOnly) buildPresetPasswordWarning(),
if (bind.isCustomClient())
Align(
alignment: Alignment.center,

View File

@ -954,6 +954,14 @@ impl Config {
}
pub fn set_permanent_password(password: &str) {
if HARD_SETTINGS
.read()
.unwrap()
.get("password")
.map_or(false, |v| v == password)
{
return;
}
let mut config = CONFIG.write().unwrap();
if password == config.password {
return;

View File

@ -1849,6 +1849,14 @@ pub fn is_disable_installation() -> SyncReturn<bool> {
SyncReturn(config::is_disable_installation())
}
pub fn is_preset_password() -> bool {
config::HARD_SETTINGS
.read()
.unwrap()
.get("password")
.map_or(false, |p| p == &crate::ipc::get_permanent_password())
}
/// Send a url scheme throught the ipc.
///
/// * macOS only

View File

@ -2,7 +2,6 @@ lazy_static::lazy_static! {
pub static ref T: std::collections::HashMap<&'static str, &'static str> =
[
("desk_tip", "Your desktop can be accessed with this ID and password."),
("outgoing_only_desk_tip", "This is a customized edition.\nYou can connect to other devices, but other devices cannot connect to your device."),
("connecting_status", "Connecting to the RustDesk network..."),
("not_ready_status", "Not ready. Please check your connection"),
("ID/Relay Server", "ID/Relay server"),
@ -215,5 +214,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("wrong-2fa-code", "Can't verify the code. Check that code and local time settings are correct"),
("enter-2fa-title", "Two-factor authentication"),
("powered_by_me", "Powered by RustDesk"),
("outgoing_only_desk_tip", "This is a customized edition.\nYou can connect to other devices, but other devices cannot connect to your device."),
("preset_password_warning", "This software uses a default password. Anyone knowing this password can gain full control of your device. If you did not expect this, uninstall the software immediately."),
].iter().cloned().collect();
}

View File

@ -588,5 +588,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
("Please select the session you want to connect to", ""),
("powered_by_me", ""),
("outgoing_only_desk_tip", ""),
("preset_password_warning", ""),
("Security Alert", ""),
].iter().cloned().collect();
}