[f22-branch 2/7] Use pwpolicy for the root password spoke.
bcl
installerbot-noreply at redhat.com
Tue Mar 17 23:09:16 UTC 2015
From: "Brian C. Lane" <bcl at redhat.com>
Use the new kickstart pwpolicy settings for the root password spoke.
Use the 'root' keyword, like so:
pwpolicy root --notstrict --minlen=10 --notempty
---
pyanaconda/constants.py | 5 ++--
pyanaconda/ui/gui/spokes/password.py | 46 ++++++++++++++++++++++++++++--------
pyanaconda/users.py | 7 +++++-
3 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/pyanaconda/constants.py b/pyanaconda/constants.py
index 46c8808..a046d82 100644
--- a/pyanaconda/constants.py
+++ b/pyanaconda/constants.py
@@ -138,11 +138,12 @@
PASSWORD_EMPTY_ERROR = N_("The password is empty.")
PASSWORD_CONFIRM_ERROR_GUI = N_("The passwords do not match.")
PASSWORD_CONFIRM_ERROR_TUI = N_("The passwords you entered were different. Please try again.")
-PASSWORD_WEAK = N_("The password you have provided is weak. You will have to press Done twice to confirm it.")
-PASSWORD_WEAK_WITH_ERROR = N_("The password you have provided is weak: %s. You will have to press Done twice to confirm it.")
+PASSWORD_WEAK = N_("The password you have provided is weak. %s")
+PASSWORD_WEAK_WITH_ERROR = N_("The password you have provided is weak: %s. %s")
PASSWORD_WEAK_CONFIRM = N_("You have provided a weak password. Press Done again to use anyway.")
PASSWORD_WEAK_CONFIRM_WITH_ERROR = N_("You have provided a weak password: %s. Press Done again to use anyway.")
PASSWORD_ASCII = N_("The password you have provided contains non-ASCII characters. You may not be able to switch between keyboard layouts to login. Press Done to continue.")
+PASSWORD_DONE_TWICE = N_("You will have to press Done twice to confirm it.")
PASSWORD_STRENGTH_DESC = [N_("Empty"), N_("Weak"), N_("Fair"), N_("Good"), N_("Strong")]
diff --git a/pyanaconda/ui/gui/spokes/password.py b/pyanaconda/ui/gui/spokes/password.py
index a7a65fb..ffbe40f 100644
--- a/pyanaconda/ui/gui/spokes/password.py
+++ b/pyanaconda/ui/gui/spokes/password.py
@@ -32,6 +32,7 @@
from pyanaconda.constants import PASSWORD_EMPTY_ERROR, PASSWORD_CONFIRM_ERROR_GUI,\
PASSWORD_STRENGTH_DESC, PASSWORD_WEAK, PASSWORD_WEAK_WITH_ERROR,\
+ PASSWORD_WEAK_CONFIRM, PASSWORD_WEAK_CONFIRM_WITH_ERROR, PASSWORD_DONE_TWICE,\
PW_ASCII_CHARS, PASSWORD_ASCII
__all__ = ["PasswordSpoke"]
@@ -86,6 +87,7 @@ def initialize(self):
self.add_check(self.confirm, self._checkPasswordEmpty)
# Counters for checks that ask the user to click Done to confirm
+ self._waiveStrengthClicks = 0
self._waiveASCIIClicks = 0
# Password validation data
@@ -105,6 +107,11 @@ def initialize(self):
self.pw_bar.add_offset_value("medium", 3)
self.pw_bar.add_offset_value("high", 4)
+ # Configure the password policy, if available. Otherwise use defaults.
+ self.policy = self.data.pwpolicy.get_policy("root")
+ if not self.policy:
+ self.policy = self.data.pwpolicy.handler.PwPolicyData()
+
def refresh(self):
# Enable the input checks in case they were disabled on the last exit
for check in self.checks:
@@ -161,7 +168,7 @@ def _checkPasswordEmpty(self, inputcheck):
"""Check whether a password has been specified at all."""
# If the password was set by kickstart, skip this check
- if self._kickstarted:
+ if self._kickstarted and not self.policy.changesok:
return InputCheck.CHECK_OK
if not self.get_input(inputcheck.input_obj):
@@ -208,9 +215,10 @@ def _updatePwQuality(self, editable=None, data=None):
pwtext = self.pw.get_text()
# Reset the counters used for the "press Done twice" logic
+ self._waiveStrengthClicks = 0
self._waiveASCIIClicks = 0
- self._pwq_valid, strength, self._pwq_error = validatePassword(pwtext, "root")
+ self._pwq_valid, strength, self._pwq_error = validatePassword(pwtext, "root", minlen=self.policy.minlen)
if not pwtext:
val = 0
@@ -244,14 +252,29 @@ def _checkPasswordStrength(self, inputcheck):
if (not self._pwq_valid) and (self._pwq_error):
return self._pwq_error
- pwstrength = self.pw_bar.get_value()
+ # use strength from policy, not bars
+ _valid, pwstrength, _error = validatePassword(pw, "root", minlen=self.policy.minlen)
- if pwstrength < 2:
+ if pwstrength < self.policy.minquality:
# If Done has been clicked twice, waive the check
- if self._pwq_error:
- return _(PASSWORD_WEAK_WITH_ERROR) % self._pwq_error
+ if self._waiveStrengthClicks > 1:
+ return InputCheck.CHECK_OK
+ elif self._waiveStrengthClicks == 1:
+ if self._pwq_error:
+ return _(PASSWORD_WEAK_CONFIRM_WITH_ERROR) % self._pwq_error
+ else:
+ return _(PASSWORD_WEAK_CONFIRM)
else:
- return _(PASSWORD_WEAK)
+ # non-strict allows done to be clicked twice
+ if self.policy.strict:
+ done_msg = ""
+ else:
+ done_msg = _(PASSWORD_DONE_TWICE)
+
+ if self._pwq_error:
+ return _(PASSWORD_WEAK_WITH_ERROR) % (self._pwq_error, done_msg)
+ else:
+ return _(PASSWORD_WEAK) % done_msg
else:
return InputCheck.CHECK_OK
@@ -273,10 +296,13 @@ def _checkPasswordASCII(self, inputcheck):
return InputCheck.CHECK_OK
def on_back_clicked(self, button):
- # If the failed check is for non-ASCII characters,
- # add a click to the counter and check again
+ # If the failed check is for password strength or non-ASCII
+ # characters, add a click to the counter and check again
failed_check = next(self.failed_checks_with_message, None)
- if failed_check == self._pwASCIICheck:
+ if not self.policy.strict and failed_check == self._pwStrengthCheck:
+ self._waiveStrengthClicks += 1
+ self._pwStrengthCheck.update_check_status()
+ elif failed_check == self._pwASCIICheck:
self._waiveASCIIClicks += 1
self._pwASCIICheck.update_check_status()
diff --git a/pyanaconda/users.py b/pyanaconda/users.py
index 465e38a..b7f9417 100644
--- a/pyanaconda/users.py
+++ b/pyanaconda/users.py
@@ -123,7 +123,7 @@ def cryptPassword(password, algo=None):
return cryptpw
-def validatePassword(pw, user="root", settings=None):
+def validatePassword(pw, user="root", settings=None, minlen=None):
"""Check the quality of a password.
This function does three things: given a password and an optional
@@ -148,6 +148,8 @@ def validatePassword(pw, user="root", settings=None):
:param settings: an optional PWQSettings object
:type settings: pwquality.PWQSettings
+ :param int minlen: Minimum acceptable password length. If not passed,
+ use the default length from PASSWORD_MIN_LEN
:returns: A tuple containing (bool(valid), int(score), str(message))
:rtype: tuple
@@ -165,6 +167,9 @@ def validatePassword(pw, user="root", settings=None):
validatePassword.pwqsettings.minlen = PASSWORD_MIN_LEN
settings = validatePassword.pwqsettings
+ if minlen is not None:
+ settings.minlen = minlen
+
if valid:
try:
strength = settings.check(pw, None, user)
--
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/3f915bf6f0361f25c2248e4f2fb2c452b4645c71
More information about the anaconda-patches
mailing list