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/tui/spokes/__init__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py index 2f92126..fc904b3 100644 --- a/pyanaconda/ui/tui/spokes/__init__.py +++ b/pyanaconda/ui/tui/spokes/__init__.py @@ -22,7 +22,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 pwquality import PWQError +import pwquality import re from collections import namedtuple from pyanaconda.iutil import setdeepattr, getdeepattr @@ -104,6 +104,25 @@ class EditTUIDialog(NormalTUISpoke): return True
def prompt(self, entry = None): + def _validatePassword(pw, confirm): + """ Better password checking. This sets up a quality checker + to score password attempts. This is similar to the pw quality + check done in the GUI, except this only raises an error if a + password is weak. + """ + # set up quality checker + _pwq = pwquality.PWQSettings() + _pwq.read_config() + + error = validatePassword(pw, confirm) + if error: + return error + strength = _pwq.check(pw, None, None) + if strength < 50: + raise pwquality.PWQError + else: + return None + if not entry: return None
@@ -114,11 +133,11 @@ class EditTUIDialog(NormalTUISpoke): # just returning an error is either blank or mismatched # passwords. Raising is because of poor quality. try: - error = validatePassword(pw, confirm) + error = _validatePassword(pw, confirm) if error: print(error) return None - except PWQError as e: + except pwquality.PWQError as e: error = _("You have provided a weak password: %s. " % e.message) error += _("\nWould you like to use it anyway?") question_window = YesNoDialog(self._app, error)
On 08/29/2013 01:43 PM, Samantha N. Bueno wrote:
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/tui/spokes/__init__.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/pyanaconda/ui/tui/spokes/__init__.py b/pyanaconda/ui/tui/spokes/__init__.py index 2f92126..fc904b3 100644 --- a/pyanaconda/ui/tui/spokes/__init__.py +++ b/pyanaconda/ui/tui/spokes/__init__.py @@ -22,7 +22,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 pwquality import PWQError +import pwquality import re from collections import namedtuple from pyanaconda.iutil import setdeepattr, getdeepattr @@ -104,6 +104,25 @@ class EditTUIDialog(NormalTUISpoke): return True
def prompt(self, entry = None):
def _validatePassword(pw, confirm):
""" Better password checking. This sets up a quality checker
to score password attempts. This is similar to the pw quality
check done in the GUI, except this only raises an error if a
password is weak.
"""
# set up quality checker
_pwq = pwquality.PWQSettings()
_pwq.read_config()
error = validatePassword(pw, confirm)
if error:
return error
strength = _pwq.check(pw, None, None)
if strength < 50:
raise pwquality.PWQError
This should add a message for the exception handler.
Can we change users.validatePassword into something that both performs the validate check and returns a strength? Both the GUI and the TUI now are duplicating work done in validatePassword, and that's not so good.
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()
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.
anaconda-patches@lists.fedorahosted.org