diff options
author | Jesse Keating <jkeating@redhat.com> | 2012-10-11 19:12:51 -0700 |
---|---|---|
committer | Jesse Keating <jkeating@redhat.com> | 2012-10-12 12:40:33 -0700 |
commit | da5d408fe339e99c9b684214dbe396e172c61578 (patch) | |
tree | ec19674950ed1608c7f52266faca98c49779cc9e | |
parent | 2591bcf528ee11d40902a6540bbb4ac3d88c4be7 (diff) | |
download | anaconda-da5d408fe339e99c9b684214dbe396e172c61578.tar.gz anaconda-da5d408fe339e99c9b684214dbe396e172c61578.tar.xz anaconda-da5d408fe339e99c9b684214dbe396e172c61578.zip |
Add a password verification method to users.py
This moves it to a more central spot so that it can be used by both the
gui and the text spoke, or any other thing that wants to validate
passwords.
-rw-r--r-- | pyanaconda/users.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/pyanaconda/users.py b/pyanaconda/users.py index c10dd4ade..f4d92d420 100644 --- a/pyanaconda/users.py +++ b/pyanaconda/users.py @@ -27,11 +27,15 @@ import tempfile import os import os.path import iutil +import pwquality from pyanaconda.constants import ROOT_PATH import logging log = logging.getLogger("anaconda") +import gettext +_ = lambda x: gettext.ldgettext("anaconda", x) + def createLuserConf(instPath, algoname='sha512'): """ Writes a libuser.conf for instPath. @@ -111,6 +115,40 @@ def cryptPassword(password, algo=None): return crypt.crypt (password, saltstr) +def validatePassword(pw, confirm, minlen=6): + # Do various steps to validate the password + # Return an error string, or None for no errors + # If inital checks pass, pwquality will be tested. Raises + # from pwquality will pass up to the calling code + + # if both pw and confirm are blank, password is disabled. + if (pw and not confirm) or (confirm and not pw): + error = _("You must enter your root password " + "and confirm it by typing it a second " + "time to continue.") + return error + + if pw != confirm: + error = _("The passwords you entered were " + "different. Please try again.") + return error + + legal = string.digits + string.ascii_letters + string.punctuation + " " + for letter in pw: + if letter not in legal: + error = _("Requested password contains " + "non-ASCII characters, which are " + "not allowed.") + return error + + if pw: + settings = pwquality.PWQSettings() + settings.read_config() + settings.minlen = minlen + settings.check(pw, None, "root") + + return None + class Users: def __init__ (self): self.admin = libuser.admin() |