Skip to content

Commit

Permalink
more specific exceptions on wrong passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Groszer committed Jan 29, 2010
1 parent e66f4a3 commit 9d281fc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
20 changes: 10 additions & 10 deletions src/z3c/password/README.txt
Expand Up @@ -167,12 +167,12 @@ We want to have at least 5 lowercase letters in the password:
>>> pwd.verify('FOOBAR123')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersLowerLetter

>>> pwd.verify('foobAR123')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersLowerLetter

>>> pwd.verify('foobaR123')

Expand All @@ -191,12 +191,12 @@ We want to have at least 5 uppercase letters in the password:
>>> pwd.verify('foobar123')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersUpperLetter

>>> pwd.verify('FOOBar123')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersUpperLetter

>>> pwd.verify('fOOBAR123')

Expand All @@ -215,12 +215,12 @@ We want to have at least 5 digits in the password:
>>> pwd.verify('foobar123')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersDigits

>>> pwd.verify('FOOBa1234')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersDigits

>>> pwd.verify('fOBA12345')

Expand All @@ -239,12 +239,12 @@ We want to have at least 5 specials in the password:
>>> pwd.verify('foo(bar)')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersSpecials

>>> pwd.verify('FO.#(Ba1)')
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersSpecials

>>> pwd.verify('fO.,;()5')

Expand All @@ -262,12 +262,12 @@ We want to have at least 5 others in the password:
>>> pwd.verify('foobar'+unichr(0x0c3)+unichr(0x0c4))
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersOthers

>>> pwd.verify('foobar'+unichr(0x0c3)+unichr(0x0c4)+unichr(0x0e1))
Traceback (most recent call last):
...
TooFewGroupCharacters
TooFewGroupCharactersOthers

>>> pwd.verify('fOO'+unichr(0x0e1)*5)

Expand Down
19 changes: 19 additions & 0 deletions src/z3c/password/interfaces.py
Expand Up @@ -43,6 +43,25 @@ class TooManyGroupCharacters(InvalidPassword):
class TooFewGroupCharacters(InvalidPassword):
__doc__ = _('''Password does not contain enough characters of one group.''')

class TooFewGroupCharactersLowerLetter(TooFewGroupCharacters):
__doc__ = _(
'''Password does not contain enough characters of lowercase letters.''')

class TooFewGroupCharactersUpperLetter(TooFewGroupCharacters):
__doc__ = _(
'''Password does not contain enough characters of uppercase letters.''')

class TooFewGroupCharactersDigits(TooFewGroupCharacters):
__doc__ = _('''Password does not contain enough characters of digits.''')

class TooFewGroupCharactersSpecials(TooFewGroupCharacters):
__doc__ = _(
'''Password does not contain enough characters of special characters.''')

class TooFewGroupCharactersOthers(TooFewGroupCharacters):
__doc__ = _(
'''Password does not contain enough characters of other characters.''')

class TooFewUniqueCharacters(InvalidPassword):
__doc__ = _('''Password does not contain enough unique characters.''')

Expand Down
10 changes: 5 additions & 5 deletions src/z3c/password/password.py
Expand Up @@ -146,23 +146,23 @@ def verify(self, new, ref=None):

if (self.minLowerLetter is not None
and num_lower_letters < self.minLowerLetter):
raise interfaces.TooFewGroupCharacters()
raise interfaces.TooFewGroupCharactersLowerLetter()

if (self.minUpperLetter is not None
and num_upper_letters < self.minUpperLetter):
raise interfaces.TooFewGroupCharacters()
raise interfaces.TooFewGroupCharactersUpperLetter()

if (self.minDigits is not None
and num_digits < self.minDigits):
raise interfaces.TooFewGroupCharacters()
raise interfaces.TooFewGroupCharactersDigits()

if (self.minSpecials is not None
and num_specials < self.minSpecials):
raise interfaces.TooFewGroupCharacters()
raise interfaces.TooFewGroupCharactersSpecials()

if (self.minOthers is not None
and num_others < self.minOthers):
raise interfaces.TooFewGroupCharacters()
raise interfaces.TooFewGroupCharactersOthers()

if (self.minUniqueCharacters is not None
and len(uniqueChars) < self.minUniqueCharacters):
Expand Down
3 changes: 1 addition & 2 deletions src/z3c/password/principal.py
Expand Up @@ -141,8 +141,7 @@ def _getRequest(self):
return None

def checkFailedAttempt(self):
#failed attempt, record it, increase counter
#(in case we have to)
#failed attempt, record it, increase counter (in case we have to)
validRequest = True
fac = self._failedAttemptCheck()
if fac == interfaces.TML_CHECK_ALL:
Expand Down

0 comments on commit 9d281fc

Please sign in to comment.