Validators

django-password-policies provides validators to check new passwords:

BaseCountValidator

class password_policies.forms.validators.BaseCountValidator

Counts the occurrences of characters of a unicodedata.category() and raises a ValidationError if the count is less than get_min_count().

get_error_message()

Returns the error message of this validator.

get_min_count()

Returns the amount of required characters.

BaseRFC4013Validator

class password_policies.forms.validators.BaseRFC4013Validator

Validates that a given password passes the requirements as defined in RFC 4013.

BaseSimilarityValidator

class password_policies.forms.validators.BaseSimilarityValidator(haystacks=[])

Compares a needle to a haystack (list of strings) and calculates a similarity between 0.0 and 1.0.

Raises a ValidationError if the similarity is greater than PASSWORD_MATCH_THRESHOLD.

haystacks = []

A list of strings.

get_treshold()
Returns:password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.

BidirectionalValidator

class password_policies.forms.validators.BidirectionalValidator

Bases: password_policies.forms.validators.BaseRFC4013Validator

Validates that

  • a string containing any RandALCat character does not contain any LCat character.
  • a string containing any RandALCat character does start and end with a RandALCat character.

For more information read RFC 4013, section 2.3.

code = u'invalid_bidirectional'

The validator’s error code.

message = <django.utils.functional.__proxy__ object at 0x105068990>

The validator’s error message.

CommonSequenceValidator

class password_policies.forms.validators.CommonSequenceValidator(haystacks=[])

Bases: password_policies.forms.validators.BaseSimilarityValidator

Validates that a given password is not based on a common sequence of characters.

code = u'invalid_common_sequence'

The validator’s error code.

message = <django.utils.functional.__proxy__ object at 0x105068a50>

The validator’s error message.

get_treshold()
Returns:password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.

ConsecutiveCountValidator

class password_policies.forms.validators.ConsecutiveCountValidator

Validates that a given password does not contain consecutive characters.

code = u'invalid_consecutive_count'

The validator’s error code.

get_max_count()
Returns:password_policies.conf.Settings.PASSWORD_MAX_CONSECUTIVE

CracklibValidator

class password_policies.forms.validators.CracklibValidator(diff_ok=0, dig_credit=0, low_credit=0, min_length=0, oth_credit=0, up_credit=0)

Validates a given password using Python bindings for cracklib.

code = u'invalid_cracklib'

The validator’s error code.

diff_ok = 0

This argument will change the default of 10 for the number of characters in the new password that must not be present in the old password. In addition, if 1/2 of the characters in the new password are different then the new password will be accepted anyway.

dig_credit = 0

The maximum credit for having digits in the new password.

low_credit = 0

The maximum credit for having lower case letters in the new password.

min_length = 6

The minimum acceptable size for the new password (plus one if credits are not disabled which is the default).

oth_credit = 0

The maximum credit for having other characters in the new password.

up_credit = 0

The maximum credit for having upper case letters in the new password.

Note

For additional informations please consult the Python bindings for cracklib documentation.

DictionaryValidator

class password_policies.forms.validators.DictionaryValidator(dictionary='', words=[])

Bases: password_policies.forms.validators.BaseSimilarityValidator

Validates that a given password is not based on a dictionary word.

Note

If dictionary AND words are empty or set to None validation is not performed.

Warning

This validator is very time consuming and validation duration depends on the amount of lines in the dictionary file. The larger the dictionary file, the longer validation takes!

code = u'invalid_dictionary_word'

The validator’s error code.

message = <django.utils.functional.__proxy__ object at 0x105068cd0>

The validator’s error message.

dictionary = ''

A path to a file with one word per line. Defaults to password_policies.conf.Settings.PASSWORD_DICTIONARY.

words = []

A list of unicode strings. Defaults to password_policies.conf.Settings.PASSWORD_WORDS.

get_treshold()
Returns:password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.

EntropyValidator

class password_policies.forms.validators.EntropyValidator

Validates that a password contains varied characters by calculating the Shannon entropy of a password.

code = u'invalid_entropy'

The validator’s error code.

long_min_entropy = 5.3

Specifies the minimum entropy of long passwords (len(password) >= 100). Defaults to password_policies.conf.Settings.PASSWORD_MIN_ENTROPY_LONG.

If set to 0 validation will not be performed.

message = <django.utils.functional.__proxy__ object at 0x105068bd0>

The validator’s error message.

short_min_entropy = 0.8

Specifies the minimum entropy of short passwords (len(password) < 100). Defaults to password_policies.conf.Settings.PASSWORD_MIN_ENTROPY_SHORT.

If set to 0 validation will not be performed.

InvalidCharacterValidator

class password_policies.forms.validators.InvalidCharacterValidator

Bases: password_policies.forms.validators.BaseRFC4013Validator

Validates that a given password does not contain invalid unicode characters as defined in RFC 4013, section 2.3.

code = u'invalid_unicode'

The validator’s error code.

message = <django.utils.functional.__proxy__ object at 0x105068d50>

The validator’s error message.

LetterCountValidator

class password_policies.forms.validators.LetterCountValidator

Bases: password_policies.forms.validators.BaseCountValidator

Counts the occurrences of letters and raises a ValidationError if the count is less than get_min_count().

categories = ['LC', 'Ll', 'Lu', 'Lt', 'Lo', 'Nl']

The unicode data letter categories:

Code Description
LC Letter, Cased
Ll Letter, Lowercase
Lu Letter, Uppercase
Lt Letter, Titlecase
Lo Letter, Other
Nl Number, Letter
code = u'invalid_letter_count'

The validator’s error code.

get_error_message()

Returns this validator’s error message.

get_min_count()
Returns:password_policies.conf.Settings.PASSWORD_MIN_LETTERS

NotEmailValidator

class password_policies.forms.validators.NotEmailValidator

Validates that a given password is not similar to an email address.

code = u'invalid_email_used'

The validator’s error code.

message = <django.utils.functional.__proxy__ object at 0x105068e10>

The validator’s error message.

NumberCountValidator

class password_policies.forms.validators.NumberCountValidator

Bases: password_policies.forms.validators.BaseCountValidator

Counts the occurrences of numbers (digits, etc.) and raises a ValidationError if the count is less than get_min_count().

categories = ['Nd', 'No']

The unicode data number categories:

Code Description
Nd Number, Decimal Digit
No Number, Other
code = u'invalid_number_count'

The validator’s error code.

get_error_message()

Returns this validator’s error message.

get_min_count()
Returns:password_policies.conf.Settings.PASSWORD_MIN_NUMBERS

SymbolCountValidator

class password_policies.forms.validators.SymbolCountValidator

Bases: password_policies.forms.validators.BaseCountValidator

Counts the occurrences of other characters than letters and numbers, except line breaks, and raises a ValidationError if the count is less than get_min_count().

categories = ['Lm', 'Mc', 'Me', 'Mn', 'Pc', 'Pd', 'Pe', 'Pf', 'Pi', 'Po', 'Ps', 'Sc', 'Sk', 'Sm', 'So', 'Zl']

The unicode data symbol categories:

Code Description
Lm Letter, Modifier
Mc Mark, Spacing Combining
Me Mark, Enclosing
Mn Mark, Nonspacing
Pc Punctuation, Connector
Pd Punctuation, Dash
Pe Punctuation, Close
Pf Punctuation, Final quote (may behave like Ps or Pe depending on usage)
Pi Punctuation, Initial quote (may behave like Ps or Pe depending on usage)
Po Punctuation, Other
Ps Punctuation, Open
Sc Symbol, Currency
Sk Symbol, Modifier
Sm Symbol, Math
So Symbol, Other
Zl Separator, Line
code = u'invalid_symbol_count'

The validator’s error code.

get_error_message()

Returns this validator’s error message.

get_min_count()
Returns:password_policies.conf.Settings.PASSWORD_MIN_SYMBOLS

validate_bidirectional

password_policies.forms.validators.validate_bidirectional

A BidirectionalValidator instance.

validate_common_sequences

password_policies.forms.validators.validate_common_sequences

A CommonSequenceValidator instance.

validate_consecutive_count

password_policies.forms.validators.validate_consecutive_count

A ConsecutiveCountValidator instance.

validate_cracklib

password_policies.forms.validators.validate_cracklib

A CracklibValidator instance.

validate_dictionary_words

password_policies.forms.validators.validate_dictionary_words

A DictionaryValidator instance.

validate_entropy

password_policies.forms.validators.validate_entropy

A EntropyValidator instance.

validate_invalid_character

password_policies.forms.validators.validate_invalid_character

A InvalidCharacterValidator instance.

validate_letter_count

password_policies.forms.validators.validate_letter_count

A LetterCountValidator instance.

validate_not_email

password_policies.forms.validators.validate_not_email

A NotEmailValidator instance.

validate_number_count

password_policies.forms.validators.validate_number_count

A NumberCountValidator instance.

validate_symbol_count

password_policies.forms.validators.validate_symbol_count

A SymbolCountValidator instance.