On Thu, 2012-10-11 at 19:21 -0700, Jesse Keating wrote:
+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
You could replace for and if with:
if not all(letter in legal for letter in pw)
But I guess both are equally good, so it's up to you.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic