Skip to content

Commit

Permalink
Better error messages for invalid password exceptions.
Browse files Browse the repository at this point in the history
When you reject the user's password for being too short or too long,
it's only polite to tell them the minimum/maximum password length.

This introduces new translatable strings which haven't been translated yet.
  • Loading branch information
mgedmin committed Aug 9, 2012
1 parent 7df8951 commit 59aadde
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 45 deletions.
8 changes: 6 additions & 2 deletions CHANGES.txt
Expand Up @@ -2,10 +2,14 @@
CHANGES
=======

0.10.2 (unreleased)
0.11.0 (unreleased)
-------------------

- Nothing changed yet.
- Better error messages for invalid password exceptions (when you reject the
user's password for being too short or too long, it's only polite to tell
them what the minimum/maximum password length is).

This introduces new translatable strings which haven't been translated yet.


0.10.1 (2011-03-28)
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Expand Up @@ -23,7 +23,7 @@ def read(*rnames):

setup (
name='z3c.password',
version='0.10.2dev',
version='0.11.0dev',
author = "Stephan Richter, Roger Ineichen and the Zope Community",
author_email = "zope3-dev@zope.org",
description = "Password generation and verification utility for Zope3",
Expand Down Expand Up @@ -62,9 +62,10 @@ def read(*rnames):
'zope.component',
'zope.exceptions',
'zope.i18nmessageid',
'zope.i18n',
'zope.interface',
'zope.schema',
'zope.security',
],
zip_safe = False,
)
)
54 changes: 27 additions & 27 deletions src/z3c/password/README.txt
Expand Up @@ -81,12 +81,12 @@ letters, digits, punctuation, other), and the maximum similarity score.
>>> pwd.verify('foo')
Traceback (most recent call last):
...
TooShortPassword
TooShortPassword: Password is too short (minimum length: 8).

>>> pwd.verify('foobar-foobar')
Traceback (most recent call last):
...
TooLongPassword
TooLongPassword: Password is too long (maximum length: 12).

>>> pwd.verify('fooBar12')

Expand All @@ -100,7 +100,7 @@ letters, digits, punctuation, other), and the maximum similarity score.
>>> pwd.verify('fooBar12', 'foobar12')
Traceback (most recent call last):
...
TooSimilarPassword
TooSimilarPassword: Password is too similar to old one (similarity 88%, should be at most 60%).

- The final check ensures that the password does not have too many characters
of one group. The groups are: lower letters, upper letters, digits,
Expand All @@ -109,27 +109,27 @@ letters, digits, punctuation, other), and the maximum similarity score.
>>> pwd.verify('fooBarBlah')
Traceback (most recent call last):
...
TooManyGroupCharacters
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

>>> pwd.verify('FOOBARBlah')
Traceback (most recent call last):
...
TooManyGroupCharacters
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

>>> pwd.verify('12345678')
Traceback (most recent call last):
...
TooManyGroupCharacters
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

>>> pwd.verify('........')
Traceback (most recent call last):
...
TooManyGroupCharacters
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

>>> pwd.verify(unichr(0x0e1)*8)
Traceback (most recent call last):
...
TooManyGroupCharacters
TooManyGroupCharacters: Password contains too many characters of one group (should have at most 6).

Let's now verify a list of password that were provided by a bank:

Expand Down 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):
...
TooFewGroupCharactersLowerLetter
TooFewGroupCharactersLowerLetter: Password does not contain enough characters of lowercase letters (should have at least 5).

>>> pwd.verify('foobAR123')
Traceback (most recent call last):
...
TooFewGroupCharactersLowerLetter
TooFewGroupCharactersLowerLetter: Password does not contain enough characters of lowercase letters (should have at least 5).

>>> 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):
...
TooFewGroupCharactersUpperLetter
TooFewGroupCharactersUpperLetter: Password does not contain enough characters of uppercase letters (should have at least 5).

>>> pwd.verify('FOOBar123')
Traceback (most recent call last):
...
TooFewGroupCharactersUpperLetter
TooFewGroupCharactersUpperLetter: Password does not contain enough characters of uppercase letters (should have at least 5).

>>> 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):
...
TooFewGroupCharactersDigits
TooFewGroupCharactersDigits: Password does not contain enough characters of digits (should have at least 5).

>>> pwd.verify('FOOBa1234')
Traceback (most recent call last):
...
TooFewGroupCharactersDigits
TooFewGroupCharactersDigits: Password does not contain enough characters of digits (should have at least 5).

>>> 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):
...
TooFewGroupCharactersSpecials
TooFewGroupCharactersSpecials: Password does not contain enough characters of special characters (should have at least 5).

>>> pwd.verify('FO.#(Ba1)')
Traceback (most recent call last):
...
TooFewGroupCharactersSpecials
TooFewGroupCharactersSpecials: Password does not contain enough characters of special characters (should have at least 5).

>>> 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):
...
TooFewGroupCharactersOthers
TooFewGroupCharactersOthers: Password does not contain enough characters of other characters (should have at least 5).

>>> pwd.verify('foobar'+unichr(0x0c3)+unichr(0x0c4)+unichr(0x0e1))
Traceback (most recent call last):
...
TooFewGroupCharactersOthers
TooFewGroupCharactersOthers: Password does not contain enough characters of other characters (should have at least 5).

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

Expand All @@ -288,12 +288,12 @@ We want to have at least 5 different characters in the password:
>>> pwd.verify('foofoo1212')
Traceback (most recent call last):
...
TooFewUniqueCharacters
TooFewUniqueCharacters: Password does not contain enough unique characters (should have at least 5).

>>> pwd.verify('FOOfoo2323')
Traceback (most recent call last):
...
TooFewUniqueCharacters
TooFewUniqueCharacters: Password does not contain enough unique characters (should have at least 5).

>>> pwd.verify('fOOBAR123')

Expand All @@ -312,12 +312,12 @@ We want to have at least 5 different letters in the password:
>>> pwd.verify('foofoo1212')
Traceback (most recent call last):
...
TooFewUniqueLetters
TooFewUniqueLetters: Password does not contain enough unique letters (should have at least 5).

>>> pwd.verify('FOOBfoob2323')
Traceback (most recent call last):
...
TooFewUniqueLetters
TooFewUniqueLetters: Password does not contain enough unique letters (should have at least 5).

>>> pwd.verify('fOOBAR123')

Expand Down Expand Up @@ -356,7 +356,7 @@ Let's validate a value:
>>> pwdField.validate(u'fooBar')
Traceback (most recent call last):
...
TooShortPassword
TooShortPassword: Password is too short (minimum length: 8).

Validation must work on bound fields too:

Expand All @@ -379,7 +379,7 @@ Bind the field:
>>> bound.validate(u'fooBar')
Traceback (most recent call last):
...
TooShortPassword
TooShortPassword: Password is too short (minimum length: 8).

Let's create a principal without the PrincipalMixIn:

Expand All @@ -394,7 +394,7 @@ Bind the field:
>>> bound.validate(u'fooBar')
Traceback (most recent call last):
...
TooShortPassword
TooShortPassword: Password is too short (minimum length: 8).


Other common usecase is to do a utility and specify it's name as checker.
Expand All @@ -415,7 +415,7 @@ Let's validate a value:
>>> pwdField.validate(u'fooBar')
Traceback (most recent call last):
...
TooShortPassword
TooShortPassword: Password is too short (minimum length: 8).


Edge cases.
Expand Down Expand Up @@ -456,4 +456,4 @@ Bound object does not have the property:

Validation silently succeeds:

>>> bound.validate(u'fooBar12')
>>> bound.validate(u'fooBar12')

0 comments on commit 59aadde

Please sign in to comment.