user-accounts: User friendly password hints
https://bugzilla.gnome.org/show_bug.cgi?id=689344
This commit is contained in:
parent
3af1b72691
commit
58348f6fd2
3 changed files with 74 additions and 21 deletions
|
@ -111,6 +111,7 @@ GOA_REQUIRED_VERSION=3.9.1
|
|||
ACCOUNTSSERVICE_REQUIRED_VERSION=0.6.30
|
||||
COLORD_REQUIRED_VERSION=0.1.34
|
||||
COLORD_GTK_REQUIRED_VERSION=0.1.24
|
||||
PWQAULITY_REQUIRED_VERSION=1.2.0
|
||||
|
||||
COMMON_MODULES="gtk+-3.0 >= $GTK_REQUIRED_VERSION
|
||||
glib-2.0 >= $GLIB_REQUIRED_VERSION
|
||||
|
@ -170,7 +171,7 @@ PKG_CHECK_MODULES(USER_ACCOUNTS_PANEL, $COMMON_MODULES
|
|||
polkit-gobject-1 >= $POLKIT_REQUIRED_VERSION
|
||||
gnome-desktop-3.0
|
||||
gdk-pixbuf-2.0 >= $GDKPIXBUF_REQUIRED_VERSION
|
||||
pwquality
|
||||
pwquality >= $PWQAULITY_REQUIRED_VERSION
|
||||
accountsservice >= $ACCOUNTSSERVICE_REQUIRED_VERSION)
|
||||
PKG_CHECK_MODULES(SHARING_PANEL, $COMMON_MODULES egg-list-box)
|
||||
PKG_CHECK_MODULES(REMOTE_LOGIN_HELPER, glib-2.0 >= $GLIB_REQUIRED_VERSION gio-2.0)
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
|
||||
#include <pwquality.h>
|
||||
|
||||
|
||||
static pwquality_settings_t *
|
||||
get_pwq (void)
|
||||
{
|
||||
|
@ -74,6 +73,52 @@ pw_generate (void)
|
|||
return res;
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
pw_error_hint (gint error)
|
||||
{
|
||||
switch (error) {
|
||||
case PWQ_ERROR_SAME_PASSWORD:
|
||||
return C_("Password hint", "The new password needs to be different from the old one.");
|
||||
case PWQ_ERROR_CASE_CHANGES_ONLY:
|
||||
return C_("Password hint", "Try changing some letters and numbers.");
|
||||
case PWQ_ERROR_TOO_SIMILAR:
|
||||
return C_("Password hint", "Try changing the password a bit more.");
|
||||
case PWQ_ERROR_USER_CHECK:
|
||||
return C_("Password hint", "A password without your user name would be stronger.");
|
||||
case PWQ_ERROR_GECOS_CHECK:
|
||||
return C_("Password hint", "Try to avoid using your name in the password.");
|
||||
case PWQ_ERROR_BAD_WORDS:
|
||||
return C_("Password hint", "Try to avoid some of the words included in the password.");
|
||||
case PWQ_ERROR_ROTATED:
|
||||
return C_("Password hint", "Try changing the password a bit more.");
|
||||
case PWQ_ERROR_CRACKLIB_CHECK:
|
||||
return C_("Password hint", "Try to avoid common words.");
|
||||
case PWQ_ERROR_PALINDROME:
|
||||
return C_("Password hint", "Try to avoid reordering existing words.");
|
||||
case PWQ_ERROR_MIN_DIGITS:
|
||||
return C_("Password hint", "Try to use more numbers.");
|
||||
case PWQ_ERROR_MIN_UPPERS:
|
||||
return C_("Password hint", "Try to use more uppercase letters.");
|
||||
case PWQ_ERROR_MIN_LOWERS:
|
||||
return C_("Password hint", "Try to use more lowercase letters.");
|
||||
case PWQ_ERROR_MIN_OTHERS:
|
||||
return C_("Password hint", "Try to use more special characters, like punctuation.");
|
||||
case PWQ_ERROR_MIN_CLASSES:
|
||||
return C_("Password hint", "Try to use a mixture of letters, numbers and punctuation.");
|
||||
case PWQ_ERROR_MAX_CONSECUTIVE:
|
||||
return C_("Password hint", "Try to avoid repeating the same character.");
|
||||
case PWQ_ERROR_MAX_CLASS_REPEAT:
|
||||
return C_("Password hint", "Try to avoid repeating the same type of character: you need to mix up letters, numbers and punctuation.");
|
||||
case PWQ_ERROR_MAX_SEQUENCE:
|
||||
return C_("Password hint", "Try to avoid sequences like 1234 or abcd.");
|
||||
case PWQ_ERROR_MIN_LENGTH:
|
||||
return C_("Password hint", "Try to add more characters.");
|
||||
case PWQ_ERROR_EMPTY_PASSWORD:
|
||||
default:
|
||||
return C_("Password hint", "Mix uppercase and lowercase and use a number or two.");
|
||||
}
|
||||
}
|
||||
|
||||
gdouble
|
||||
pw_strength (const gchar *password,
|
||||
const gchar *old_password,
|
||||
|
@ -90,38 +135,44 @@ pw_strength (const gchar *password,
|
|||
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);
|
||||
goto out;
|
||||
}
|
||||
else if (rv < 0) {
|
||||
*hint = C_("Password strength", "Not good enough");
|
||||
*long_hint = pwquality_strerror (NULL, 0, rv, auxerror);
|
||||
goto out;
|
||||
}
|
||||
|
||||
strength = CLAMP (0.01 * rv, 0.0, 1.0);
|
||||
|
||||
if (strength < 0.50) {
|
||||
if (rv < 0) {
|
||||
*hint = C_("Password strength", "Strength: Weak");
|
||||
}
|
||||
else if (strength < 0.50) {
|
||||
level = 1;
|
||||
*hint = C_("Password strength", "Weak");
|
||||
*hint = C_("Password strength", "Strength: Low");
|
||||
} else if (strength < 0.75) {
|
||||
level = 2;
|
||||
*hint = C_("Password strength", "Fair");
|
||||
*hint = C_("Password strength", "Strength: Medium");
|
||||
} else if (strength < 0.90) {
|
||||
level = 3;
|
||||
*hint = C_("Password strength", "Good");
|
||||
*hint = C_("Password strength", "Strength: Good");
|
||||
} else {
|
||||
level = 4;
|
||||
*hint = C_("Password strength", "Strong");
|
||||
*hint = C_("Password strength", "Strength: High");
|
||||
}
|
||||
|
||||
*long_hint = NULL;
|
||||
*long_hint = pw_error_hint (rv);
|
||||
|
||||
out:
|
||||
if (strength_level)
|
||||
*strength_level = level;
|
||||
|
||||
return strength;
|
||||
}
|
||||
|
||||
int
|
||||
pw_strenght_hint_get_width_chars ()
|
||||
{
|
||||
gint len;
|
||||
|
||||
len = 0;
|
||||
len = MAX (len, strlen (C_("Password strength", "Strength: Weak")));
|
||||
len = MAX (len, strlen (C_("Password strength", "Strength: Low")));
|
||||
len = MAX (len, strlen (C_("Password strength", "Strength: Medium")));
|
||||
len = MAX (len, strlen (C_("Password strength", "Strength: Good")));
|
||||
len = MAX (len, strlen (C_("Password strength", "Strength: High")));
|
||||
len += 2;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
|
|
@ -29,3 +29,4 @@ gdouble pw_strength (const gchar *password,
|
|||
const gchar **hint,
|
||||
const gchar **long_hints,
|
||||
gint *strength_level);
|
||||
int pw_strenght_hint_get_width_chars ();
|
||||
|
|
Loading…
Add table
Reference in a new issue