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
This commit is contained in:
Ondrej Holy 2017-04-05 13:29:30 +02:00 committed by Felipe Borges
parent 9e4123363e
commit e89d4f59c2
5 changed files with 23 additions and 13 deletions

View file

@ -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);