usage
by Ted X Toth
I'm trying to understand how to use pwquality to 'check' a password. I've tried to construct a PWQSettings object to require that a password have at least 1 uppercase letter, 1 lowercase letter, 1 numeric digit, 1 symbol character and be at least 12 characters long. However when I check a password without any uppercase letter (test 1) I don't get back the error PWQ_ERROR_MIN_UPPERS like I would expect. Also constructing a PWQSettings object with only the pwquality_settings option specified (test 2) I get:
Traceback (most recent call last):
File "test.py", line 14, in
request = PasswordCheckRequest(pwquality_settings=settings)
TypeError: **init**() takes at least 2 arguments (2 given)
which I don't understand since the error indicates the 2 arguments were given despite only one actually was.
I've included other tests which also do not return the errors expected based on the options specified.
Can someone help me, please?
import pwquality
from pyanaconda.users import PasswordCheckRequest
settings = pwquality.PWQSettings()
settings.set_option("ucredit=1")
settings.set_option("dcredit=1")
settings.set_option("lcredit=1")
settings.set_option("minlen=12")
settings.set_option("ocredit=1")
#test 1
request = PasswordCheckRequest(password="9ol.<ki_7ujm", pwquality_settings=settings) r = settings.check("9ol.<ki_7ujm", None, "foo")
print "test 1", r
#test 2
try:
request = PasswordCheckRequest(pwquality_settings=settings)
r = settings.check("9ol.<KI*7", None, "foo")
print "test 2", r
except Exception, ex:
print ex.message
request = PasswordCheckRequest(password="9ol.<KI_7", minimum_length=12, username="foo", pwquality_settings=settings, name_of_password="foo") r = settings.check("9ol.<KI_7", None, "foo")
print "test 3", r
request = PasswordCheckRequest(password="ol.<KI_abcdefg", minimum_length=12, username="foo", pwquality_settings=settings, name_of_password="foo") r = settings.check("ol.<KI_abcdefg", None, "foo")
print "test 4", r
request = PasswordCheckRequest(password="ol.<ki_abcdefg", minimum_length=12, username="foo", pwquality_settings=settings, name_of_password="foo") r = settings.check("ol.<ki_abcdefg", None, "foo")
print "test 5", r
5 years, 1 month