[PATCH, v02] Warn user if they enter a weak password in TUI. (#1001039)
David Shea
dshea at redhat.com
Tue Sep 3 18:55:18 UTC 2013
On 09/03/2013 01:09 PM, Samantha N. Bueno wrote:
> As per dshea's recommendations, here's a new/revised version with
> appropriate edits.
>
> This is in keeping some consistency with GUI behavior, check a user's
> pw quality score and warn/prompt them to confirm whether they are ok
> with using a weak pw.
>
> Resolves: rhbz#1001039
> ---
> pyanaconda/ui/gui/spokes/password.py | 12 +++---------
> pyanaconda/ui/tui/spokes/__init__.py | 5 ++++-
> pyanaconda/users.py | 8 ++++++++
> 3 files changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
> index c67979b..55bf116 100644
> --- a/pyanaconda/ui/gui/spokes/password.py
> +++ b/pyanaconda/ui/gui/spokes/password.py
> @@ -20,15 +20,13 @@
> #
>
> from pyanaconda.i18n import _, N_
> -from pyanaconda.users import cryptPassword, validatePassword
> +from pyanaconda.users import cryptPassword, validatePassword, checkPassword
> from pwquality import PWQError
>
> from pyanaconda.ui.gui.spokes import NormalSpoke
> from pyanaconda.ui.gui.categories.user_settings import UserSettingsCategory
> from pyanaconda.ui.common import FirstbootSpokeMixIn
>
> -import pwquality
> -
> __all__ = ["PasswordSpoke"]
>
>
> @@ -61,10 +59,6 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
> self.pw.set_placeholder_text(_("The password is set."))
> self.confirm.set_placeholder_text(_("The password is set."))
>
> - # set up passphrase quality checker
> - self._pwq = pwquality.PWQSettings()
> - self._pwq.read_config()
> -
> self.pw_bar = self.builder.get_object("password_bar")
> self.pw_label = self.builder.get_object("password_label")
>
> @@ -113,9 +107,9 @@ class PasswordSpoke(FirstbootSpokeMixIn, NormalSpoke):
> the changed Gtk event handler.
> """
> try:
> - strength = self._pwq.check(self.pw.get_text(), None, None)
> + strength = checkPassword(self.pw.get_text())
> _pwq_error = None
> - except pwquality.PWQError as e:
> + except PWQError as e:
> _pwq_error = e.message
> strength = 0
>
> diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py
> index 2f92126..087199b 100644
> --- a/pyanaconda/ui/tui/spokes/__init__.py
> +++ b/pyanaconda/ui/tui/spokes/__init__.py
> @@ -21,7 +21,7 @@
> from pyanaconda.ui.tui import simpleline as tui
> from pyanaconda.ui.tui.tuiobject import TUIObject, YesNoDialog
> from pyanaconda.ui.common import Spoke, StandaloneSpoke, NormalSpoke, PersonalizationSpoke, collect
> -from pyanaconda.users import validatePassword
> +from pyanaconda.users import validatePassword, checkPassword
> from pwquality import PWQError
> import re
> from collections import namedtuple
> @@ -118,6 +118,9 @@ class EditTUIDialog(NormalTUISpoke):
> if error:
> print(error)
> return None
> + strength = checkPassword(pw)
> + if strength < 50:
> + raise PWQError("The password you have provided is weak.")
> except PWQError as e:
> error = _("You have provided a weak password: %s. " % e.message)
> error += _("\nWould you like to use it anyway?")
> diff --git a/pyanaconda/users.py b/pyanaconda/users.py
> index 33f86fe..ba5427a 100644
> --- a/pyanaconda/users.py
> +++ b/pyanaconda/users.py
> @@ -145,6 +145,14 @@ def validatePassword(pw, confirm=None, minlen=6, user="root"):
>
> return None
>
> +def checkPassword(pw):
> + """ Check the quality of a password passed in and return a numeric
> + value.
> + """
> + pwq = pwquality.PWQSettings()
> + pwq.read_config()
> + return pwq.check(pw, None, None)
> +
> def guess_username(fullname):
> fullname = fullname.split()
>
Ack.
More information about the anaconda-patches
mailing list