[gnome-control-center] users: Pass more information to password checker



commit f62d8016562c96dc701a6e6ad8cb2ce1aaba7b78
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat May 19 17:45:04 2012 -0400

    users: Pass more information to password checker
    
    Passing the username and the old password allows the password
    quality check find more bad passwords. Also, add a way to provide
    more information about why a password is not good enough.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=676396

 panels/user-accounts/pw-utils.c           |   11 +++++++++--
 panels/user-accounts/pw-utils.h           |    5 ++++-
 panels/user-accounts/um-password-dialog.c |   10 +++++++++-
 3 files changed, 22 insertions(+), 4 deletions(-)
---
diff --git a/panels/user-accounts/pw-utils.c b/panels/user-accounts/pw-utils.c
index dcd831b..8d2fde0 100644
--- a/panels/user-accounts/pw-utils.c
+++ b/panels/user-accounts/pw-utils.c
@@ -76,22 +76,27 @@ pw_generate (void)
 
 gdouble
 pw_strength (const gchar  *password,
-             const gchar **hint)
+             const gchar  *old_password,
+             const gchar  *username,
+             const gchar **hint,
+             const gchar **long_hint)
 {
         gint rv;
         gdouble strength;
         void *auxerror;
 
         rv = pwquality_check (get_pwq (),
-                              password, NULL, NULL,
+                              password, old_password, username,
                               &auxerror);
 
         if (rv == PWQ_ERROR_MIN_LENGTH) {
                 *hint = C_("Password strength", "Too short");
+                *long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
                 return 0.0;
         }
         else if (rv < 0) {
                 *hint = C_("Password strength", "Not good enough");
+                *long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
                 return 0.0;
         }
 
@@ -106,5 +111,7 @@ pw_strength (const gchar  *password,
         else
                 *hint = C_("Password strength", "Strong");
 
+        *long_hint = NULL;
+
          return strength;
 }
diff --git a/panels/user-accounts/pw-utils.h b/panels/user-accounts/pw-utils.h
index 9e4ad0b..a88ae34 100644
--- a/panels/user-accounts/pw-utils.h
+++ b/panels/user-accounts/pw-utils.h
@@ -24,4 +24,7 @@
 gint     pw_min_length (void);
 gchar   *pw_generate   (void);
 gdouble  pw_strength   (const gchar  *password,
-                        const gchar **hint);
+                        const gchar  *old_password,
+                        const gchar  *username,
+                        const gchar **hint,
+                        const gchar **long_hints);
diff --git a/panels/user-accounts/um-password-dialog.c b/panels/user-accounts/um-password-dialog.c
index 991756b..8660594 100644
--- a/panels/user-accounts/um-password-dialog.c
+++ b/panels/user-accounts/um-password-dialog.c
@@ -314,15 +314,23 @@ static void
 update_password_strength (UmPasswordDialog *um)
 {
         const gchar *password;
+        const gchar *old_password;
+        const gchar *username;
         gdouble strength;
         const gchar *hint;
+        const gchar *long_hint;
 
         password = gtk_entry_get_text (GTK_ENTRY (um->password_entry));
+        old_password = gtk_entry_get_text (GTK_ENTRY (um->old_password_entry));
+        username = um_user_get_user_name (um->user);
 
-        strength = pw_strength (password, &hint);
+        strength = pw_strength (password, old_password, username,
+                                &hint, &long_hint);
 
         cc_strength_bar_set_fraction (CC_STRENGTH_BAR (um->strength_indicator), strength);
         gtk_label_set_label (GTK_LABEL (um->strength_indicator_label), hint);
+        gtk_widget_set_tooltip_text (um->strength_indicator, long_hint);
+        gtk_widget_set_tooltip_text (um->strength_indicator_label, long_hint);
 }
 
 static void



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