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
This commit is contained in:
Matthias Clasen 2012-05-19 17:45:04 -04:00
parent 810f29b6ce
commit f62d801656
3 changed files with 22 additions and 4 deletions

View file

@ -76,22 +76,27 @@ pw_generate (void)
gdouble gdouble
pw_strength (const gchar *password, pw_strength (const gchar *password,
const gchar **hint) const gchar *old_password,
const gchar *username,
const gchar **hint,
const gchar **long_hint)
{ {
gint rv; gint rv;
gdouble strength; gdouble strength;
void *auxerror; void *auxerror;
rv = pwquality_check (get_pwq (), rv = pwquality_check (get_pwq (),
password, NULL, NULL, password, old_password, username,
&auxerror); &auxerror);
if (rv == PWQ_ERROR_MIN_LENGTH) { if (rv == PWQ_ERROR_MIN_LENGTH) {
*hint = C_("Password strength", "Too short"); *hint = C_("Password strength", "Too short");
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
return 0.0; return 0.0;
} }
else if (rv < 0) { else if (rv < 0) {
*hint = C_("Password strength", "Not good enough"); *hint = C_("Password strength", "Not good enough");
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
return 0.0; return 0.0;
} }
@ -106,5 +111,7 @@ pw_strength (const gchar *password,
else else
*hint = C_("Password strength", "Strong"); *hint = C_("Password strength", "Strong");
*long_hint = NULL;
return strength; return strength;
} }

View file

@ -24,4 +24,7 @@
gint pw_min_length (void); gint pw_min_length (void);
gchar *pw_generate (void); gchar *pw_generate (void);
gdouble pw_strength (const gchar *password, gdouble pw_strength (const gchar *password,
const gchar **hint); const gchar *old_password,
const gchar *username,
const gchar **hint,
const gchar **long_hints);

View file

@ -314,15 +314,23 @@ static void
update_password_strength (UmPasswordDialog *um) update_password_strength (UmPasswordDialog *um)
{ {
const gchar *password; const gchar *password;
const gchar *old_password;
const gchar *username;
gdouble strength; gdouble strength;
const gchar *hint; const gchar *hint;
const gchar *long_hint;
password = gtk_entry_get_text (GTK_ENTRY (um->password_entry)); 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); cc_strength_bar_set_fraction (CC_STRENGTH_BAR (um->strength_indicator), strength);
gtk_label_set_label (GTK_LABEL (um->strength_indicator_label), hint); 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 static void