Skip to content

Commit

Permalink
Merge pull request #14 from samuelcolvin/master
Browse files Browse the repository at this point in the history
either upper or lowercase letter support
  • Loading branch information
maccesch committed Apr 14, 2015
2 parents 641e3fc + eb6eb26 commit 35f60d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Optional:
PASSWORD_COMPLEXITY = { # You can omit any or all of these for no limit for that particular set
"UPPER": 1, # Uppercase
"LOWER": 1, # Lowercase
"LETTERS": 1, # Either uppercase or lowercase letters
"DIGITS": 1, # Digits
"PUNCTUATION": 1, # Punctuation (string.punctuation)
"SPECIAL": 1, # Not alphanumeric, space or punctuation character
Expand Down
10 changes: 8 additions & 2 deletions passwords/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,16 @@ def __call__(self, value):
if self.complexities is None:
return

uppercase, lowercase, digits = set(), set(), set()
special, punctuation = set(), set()
uppercase, lowercase, letters = set(), set(), set()
digits, special, punctuation = set(), set(), set()

for character in value:
if character.isupper():
uppercase.add(character)
letters.add(character)
elif character.islower():
lowercase.add(character)
letters.add(character)
elif character.isdigit():
digits.add(character)
elif character in string.punctuation:
Expand All @@ -99,6 +101,10 @@ def __call__(self, value):
errors.append(
_("must contain %(LOWER)s or more unique lowercase characters") %
self.complexities)
if len(letters) < self.complexities.get("LETTERS", 0):
errors.append(
_("must contain %(LETTERS)s or more unique letters") %
self.complexities)
if len(digits) < self.complexities.get("DIGITS", 0):
errors.append(
_("must contain %(DIGITS)s or more unique digits") %
Expand Down
16 changes: 16 additions & 0 deletions tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ def test_minimum_lowercase_count(self):
self.assertInvalid(cv, 'sOME lOWERCASE', 'lowercase')
self.assertInvalid(cv, 'all lowercase', 'lowercase')

def test_minimum_letter_count(self):
cv = self.mkvalidator(LETTERS=0)
self.assertValid(cv, '1234. ?')
self.assertValid(cv, 'soME 123')
self.assertValid(cv, 'allletters')

cv = self.mkvalidator(LETTERS=1)
self.assertInvalid(cv, '1234. ?', 'letter')
self.assertValid(cv, 'soME 123')
self.assertValid(cv, 'allletters')

cv = self.mkvalidator(LETTERS=100)
self.assertInvalid(cv, '1234. ?', 'letter')
self.assertInvalid(cv, 'soME 123', 'letter')
self.assertInvalid(cv, 'allletters', 'letter')

def test_minimum_digit_count(self):
cv = self.mkvalidator(DIGITS=0)
self.assertValid(cv, '')
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tox]
envlist =
py27-dj{12,13,14,15,16,17,18a1},
py{27,34}-dj{15,16,17,18a1}
py27-dj{12,13,14,15,16,17,18},
py{27,34}-dj{15,16,17,18}

[testenv]
commands = py.test tests
Expand All @@ -13,4 +13,4 @@ deps =
dj15: Django>=1.5,<1.6
dj16: Django>=1.6,<1.7
dj17: Django>=1.7,<1.8
dj18a1: https://www.djangoproject.com/download/1.8a1/tarball/
dj18: Django>=1.8,<1.9

0 comments on commit 35f60d7

Please sign in to comment.