Skip to content

Commit 3c028fe

Browse files
authored
feat: numeric one-time password (rustdesk#11846)
Signed-off-by: fufesou <linlong1266@gmail.com>
1 parent 6ff679c commit 3c028fe

51 files changed

Lines changed: 110 additions & 3 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

flutter/lib/consts.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ const String kOptionAllowRemoteConfigModification =
110110
"allow-remote-config-modification";
111111
const String kOptionVerificationMethod = "verification-method";
112112
const String kOptionApproveMode = "approve-mode";
113+
const String kOptionAllowNumericOneTimePassword =
114+
"allow-numeric-one-time-password";
113115
const String kOptionCollapseToolbar = "collapse_toolbar";
114116
const String kOptionShowRemoteCursor = "show_remote_cursor";
115117
const String kOptionFollowRemoteCursor = "follow_remote_cursor";

flutter/lib/desktop/pages/desktop_setting_page.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,34 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
10971097
))
10981098
.toList();
10991099

1100+
final isOptFixedNumOTP =
1101+
isOptionFixed(kOptionAllowNumericOneTimePassword);
1102+
final isNumOPTChangable = !isOptFixedNumOTP && tmpEnabled && !locked;
1103+
final numericOneTimePassword = GestureDetector(
1104+
child: InkWell(
1105+
child: Row(
1106+
children: [
1107+
Checkbox(
1108+
value: model.allowNumericOneTimePassword,
1109+
onChanged: isNumOPTChangable
1110+
? (bool? v) {
1111+
model.switchAllowNumericOneTimePassword();
1112+
}
1113+
: null)
1114+
.marginOnly(right: 5),
1115+
Expanded(
1116+
child: Text(
1117+
translate('Numeric one-time password'),
1118+
style: TextStyle(
1119+
color: disabledTextColor(context, isNumOPTChangable)),
1120+
))
1121+
],
1122+
)),
1123+
onTap: isNumOPTChangable
1124+
? () => model.switchAllowNumericOneTimePassword()
1125+
: null,
1126+
).marginOnly(left: _kContentHSubMargin - 5);
1127+
11001128
final modeKeys = <String>[
11011129
'password',
11021130
'click',
@@ -1133,6 +1161,7 @@ class _SafetyState extends State<_Safety> with AutomaticKeepAliveClientMixin {
11331161
],
11341162
),
11351163
enabled: tmpEnabled && !locked),
1164+
numericOneTimePassword,
11361165
if (usePassword) radios[1],
11371166
if (usePassword)
11381167
_SubButton('Set permanent password', setPasswordDialog,

flutter/lib/mobile/pages/server_page.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ class _DropDownAction extends StatelessWidget {
5656
final verificationMethod = gFFI.serverModel.verificationMethod;
5757
final showPasswordOption = approveMode != 'click';
5858
final isApproveModeFixed = isOptionFixed(kOptionApproveMode);
59+
final isNumericOneTimePasswordFixed =
60+
isOptionFixed(kOptionAllowNumericOneTimePassword);
61+
final isAllowNumericOneTimePassword =
62+
gFFI.serverModel.allowNumericOneTimePassword;
5963
return [
6064
PopupMenuItem(
6165
enabled: gFFI.serverModel.connectStatus > 0,
@@ -94,6 +98,14 @@ class _DropDownAction extends StatelessWidget {
9498
value: "setTemporaryPasswordLength",
9599
child: Text(translate("One-time password length")),
96100
),
101+
if (showPasswordOption &&
102+
verificationMethod != kUsePermanentPassword)
103+
PopupMenuItem(
104+
value: "allowNumericOneTimePassword",
105+
child: listTile(translate("Numeric one-time password"),
106+
isAllowNumericOneTimePassword),
107+
enabled: !isNumericOneTimePasswordFixed,
108+
),
97109
if (showPasswordOption) const PopupMenuDivider(),
98110
if (showPasswordOption)
99111
PopupMenuItem(
@@ -124,6 +136,9 @@ class _DropDownAction extends StatelessWidget {
124136
setPasswordDialog();
125137
} else if (value == "setTemporaryPasswordLength") {
126138
setTemporaryPasswordLengthDialog(gFFI.dialogManager);
139+
} else if (value == "allowNumericOneTimePassword") {
140+
gFFI.serverModel.switchAllowNumericOneTimePassword();
141+
gFFI.serverModel.updatePasswordModel();
127142
} else if (value == kUsePermanentPassword ||
128143
value == kUseTemporaryPassword ||
129144
value == kUseBothPasswords) {

flutter/lib/models/server_model.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ServerModel with ChangeNotifier {
3636
int _connectStatus = 0; // Rendezvous Server status
3737
String _verificationMethod = "";
3838
String _temporaryPasswordLength = "";
39+
bool _allowNumericOneTimePassword = false;
3940
String _approveMode = "";
4041
int _zeroClientLengthCounter = 0;
4142

@@ -112,6 +113,12 @@ class ServerModel with ChangeNotifier {
112113
*/
113114
}
114115

116+
bool get allowNumericOneTimePassword => _allowNumericOneTimePassword;
117+
switchAllowNumericOneTimePassword() async {
118+
await mainSetBoolOption(
119+
kOptionAllowNumericOneTimePassword, !_allowNumericOneTimePassword);
120+
}
121+
115122
TextEditingController get serverId => _serverId;
116123

117124
TextEditingController get serverPasswd => _serverPasswd;
@@ -227,6 +234,8 @@ class ServerModel with ChangeNotifier {
227234
final temporaryPasswordLength =
228235
await bind.mainGetOption(key: "temporary-password-length");
229236
final approveMode = await bind.mainGetOption(key: kOptionApproveMode);
237+
final numericOneTimePassword =
238+
await mainGetBoolOption(kOptionAllowNumericOneTimePassword);
230239
/*
231240
var hideCm = option2bool(
232241
'allow-hide-cm', await bind.mainGetOption(key: 'allow-hide-cm'));
@@ -265,6 +274,10 @@ class ServerModel with ChangeNotifier {
265274
_temporaryPasswordLength = temporaryPasswordLength;
266275
update = true;
267276
}
277+
if (_allowNumericOneTimePassword != numericOneTimePassword) {
278+
_allowNumericOneTimePassword = numericOneTimePassword;
279+
update = true;
280+
}
268281
/*
269282
if (_hideCm != hideCm) {
270283
_hideCm = hideCm;
@@ -817,8 +830,8 @@ class Client {
817830

818831
RxInt unreadChatMessageCount = 0.obs;
819832

820-
Client(this.id, this.authorized, this.isFileTransfer, this.isViewCamera, this.name, this.peerId,
821-
this.keyboard, this.clipboard, this.audio);
833+
Client(this.id, this.authorized, this.isFileTransfer, this.isViewCamera,
834+
this.name, this.peerId, this.keyboard, this.clipboard, this.audio);
822835

823836
Client.fromJson(Map<String, dynamic> json) {
824837
id = json['id'];

libs/hbb_common

src/lang/ar.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
698698
("Use WebSocket", ""),
699699
("Trackpad speed", ""),
700700
("Default trackpad speed", ""),
701+
("Numeric one-time password", ""),
701702
].iter().cloned().collect();
702703
}

src/lang/be.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
698698
("Use WebSocket", ""),
699699
("Trackpad speed", ""),
700700
("Default trackpad speed", ""),
701+
("Numeric one-time password", ""),
701702
].iter().cloned().collect();
702703
}

src/lang/bg.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
698698
("Use WebSocket", ""),
699699
("Trackpad speed", ""),
700700
("Default trackpad speed", ""),
701+
("Numeric one-time password", ""),
701702
].iter().cloned().collect();
702703
}

src/lang/ca.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
698698
("Use WebSocket", ""),
699699
("Trackpad speed", ""),
700700
("Default trackpad speed", ""),
701+
("Numeric one-time password", ""),
701702
].iter().cloned().collect();
702703
}

src/lang/cn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,5 +698,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
698698
("Use WebSocket", "使用 WebSocket"),
699699
("Trackpad speed", "触控板速度"),
700700
("Default trackpad speed", "默认触控板速度"),
701+
("Numeric one-time password", "一次性密码为数字"),
701702
].iter().cloned().collect();
702703
}

0 commit comments

Comments
 (0)