[gnome-control-center] user-accounts: Add strength indicator level for weak passwords



commit e89d4f59c29f7078daaa84d7c89b324d8f7c2f9c
Author: Ondrej Holy <oholy redhat com>
Date:   Wed Apr 5 13:29:30 2017 +0200

    user-accounts: Add strength indicator level for weak passwords
    
    Add first level for short, or weak passwords to be obvious that
    the strength indicator signalize something.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780002

 panels/user-accounts/data/account-dialog.ui  |    9 ++++++---
 panels/user-accounts/data/password-dialog.ui |    9 ++++++---
 panels/user-accounts/pw-utils.c              |   14 +++++++++-----
 panels/user-accounts/um-account-dialog.c     |    2 +-
 panels/user-accounts/um-password-dialog.c    |    2 +-
 5 files changed, 23 insertions(+), 13 deletions(-)
---
diff --git a/panels/user-accounts/data/account-dialog.ui b/panels/user-accounts/data/account-dialog.ui
index 03d8ffa..a508ecd 100644
--- a/panels/user-accounts/data/account-dialog.ui
+++ b/panels/user-accounts/data/account-dialog.ui
@@ -335,11 +335,14 @@
                   <object class="GtkLevelBar" id="local_strength_indicator">
                     <property name="visible">True</property>
                     <property name="mode">discrete</property>
-                    <property name="max-value">4</property>
+                    <property name="max-value">5</property>
                     <property name="hexpand">True</property>
                     <offsets>
-                      <offset name="low" value="1"/>
-                      <offset name="high" value="3"/>
+                      <offset name="strength-weak" value="1"/>
+                      <offset name="strength-low" value="2"/>
+                      <offset name="strength-medium" value="3"/>
+                      <offset name="strength-good" value="4"/>
+                      <offset name="strength-high" value="5"/>
                     </offsets>
                   </object>
                   <packing>
diff --git a/panels/user-accounts/data/password-dialog.ui b/panels/user-accounts/data/password-dialog.ui
index bf24769..283f703 100644
--- a/panels/user-accounts/data/password-dialog.ui
+++ b/panels/user-accounts/data/password-dialog.ui
@@ -187,10 +187,13 @@
                   <object class="GtkLevelBar" id="strength-indicator">
                     <property name="visible">True</property>
                     <property name="mode">discrete</property>
-                    <property name="max-value">4</property>
+                    <property name="max-value">5</property>
                     <offsets>
-                      <offset name="low" value="1"/>
-                      <offset name="high" value="3"/>
+                      <offset name="strength-weak" value="1"/>
+                      <offset name="strength-low" value="2"/>
+                      <offset name="strength-medium" value="3"/>
+                      <offset name="strength-good" value="4"/>
+                      <offset name="strength-high" value="5"/>
                     </offsets>
                   </object>
                   <packing>
diff --git a/panels/user-accounts/pw-utils.c b/panels/user-accounts/pw-utils.c
index 7c31e56..49d2f77 100644
--- a/panels/user-accounts/pw-utils.c
+++ b/panels/user-accounts/pw-utils.c
@@ -127,7 +127,7 @@ pw_strength (const gchar  *password,
              const gchar **hint,
              gint         *strength_level)
 {
-        gint rv, level = 0;
+        gint rv, level, length = 0;
         gdouble strength = 0.0;
         void *auxerror;
 
@@ -135,17 +135,21 @@ pw_strength (const gchar  *password,
                               password, old_password, username,
                               &auxerror);
 
+        if (password != NULL)
+                length = strlen (password);
+
         strength = CLAMP (0.01 * rv, 0.0, 1.0);
         if (rv < 0) {
+                level = (length > 0) ? 1 : 0;
         }
         else if (strength < 0.50) {
-                level = 1;
-        } else if (strength < 0.75) {
                 level = 2;
-        } else if (strength < 0.90) {
+        } else if (strength < 0.75) {
                 level = 3;
-        } else {
+        } else if (strength < 0.90) {
                 level = 4;
+        } else {
+                level = 5;
         }
 
         *hint = pw_error_hint (rv);
diff --git a/panels/user-accounts/um-account-dialog.c b/panels/user-accounts/um-account-dialog.c
index 94191fa..91cba2e 100644
--- a/panels/user-accounts/um-account-dialog.c
+++ b/panels/user-accounts/um-account-dialog.c
@@ -282,7 +282,7 @@ update_password_strength (UmAccountDialog *self)
         gtk_label_set_label (GTK_LABEL (self->local_hint), hint);
         gtk_level_bar_set_value (GTK_LEVEL_BAR (self->local_strength_indicator), strength_level);
 
-        if (strength_level > 0) {
+        if (strength_level > 1) {
                 set_entry_validation_checkmark (GTK_ENTRY (self->local_password));
         } else if (strlen (password) == 0) {
                 set_entry_generation_icon (GTK_ENTRY (self->local_password));
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 9b79743..6921b88 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -84,7 +84,7 @@ update_password_strength (UmPasswordDialog *um)
         gtk_level_bar_set_value (GTK_LEVEL_BAR (um->strength_indicator), strength_level);
         gtk_label_set_label (GTK_LABEL (um->password_hint), hint);
 
-        if (strength_level > 0) {
+        if (strength_level > 1) {
                 set_entry_validation_checkmark (GTK_ENTRY (um->password_entry));
         } else if (strlen (password) == 0) {
                 set_entry_generation_icon (GTK_ENTRY (um->password_entry));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]