浏览代码

Prevent users from using weak passwords

Vishnu Mohandas 4 年之前
父节点
当前提交
4b22e0fd22
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      lib/ui/password_entry_page.dart

+ 8 - 1
lib/ui/password_entry_page.dart

@@ -13,8 +13,11 @@ class PasswordEntryPage extends StatefulWidget {
 }
 }
 
 
 class _PasswordEntryPageState extends State<PasswordEntryPage> {
 class _PasswordEntryPageState extends State<PasswordEntryPage> {
+  static const kPasswordStrengthThreshold = 0.4;
+
   final _passwordController1 = TextEditingController(),
   final _passwordController1 = TextEditingController(),
       _passwordController2 = TextEditingController();
       _passwordController2 = TextEditingController();
+  double _passwordStrength = 0;
 
 
   @override
   @override
   Widget build(BuildContext context) {
   Widget build(BuildContext context) {
@@ -34,7 +37,7 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
           password: _passwordController1.text,
           password: _passwordController1.text,
           backgroundColor: Colors.grey[850],
           backgroundColor: Colors.grey[850],
           strengthCallback: (strength) {
           strengthCallback: (strength) {
-            debugPrint(strength.toString());
+            _passwordStrength = strength;
           },
           },
         ),
         ),
         Expanded(
         Expanded(
@@ -120,6 +123,10 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
                                     _passwordController2.text) {
                                     _passwordController2.text) {
                                   showErrorDialog(context, "uhm...",
                                   showErrorDialog(context, "uhm...",
                                       "the passwords you entered don't match");
                                       "the passwords you entered don't match");
+                                } else if (_passwordStrength <
+                                    kPasswordStrengthThreshold) {
+                                  showErrorDialog(context, "weak password",
+                                      "the password you have chosen is too simple, please choose another one");
                                 } else {
                                 } else {
                                   _showPasswordConfirmationDialog();
                                   _showPasswordConfirmationDialog();
                                 }
                                 }