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 aValidationErrorif the count is less thanget_min_count().- get_error_message()
Returns the error message of this validator.
- get_min_count()
Returns the amount of required characters.
BaseRFC4013Validator
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
ValidationErrorif the similarity is greater thanPASSWORD_MATCH_THRESHOLD.- haystacks = []
A list of strings.
- get_threshold()
- Returns:
password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.
BidirectionalValidator
- class password_policies.forms.validators.BidirectionalValidator
Bases:
BaseRFC4013ValidatorValidates 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 = 'invalid_bidirectional'
The validator’s error code.
- message = 'The new password contains ambiguous bidirectional characters.'
The validator’s error message.
CommonSequenceValidator
- class password_policies.forms.validators.CommonSequenceValidator(haystacks=[])
Bases:
BaseSimilarityValidatorValidates that a given password is not based on a common sequence of characters.
- code = 'invalid_common_sequence'
The validator’s error code.
- message = 'The new password is based on a common sequence of characters.'
The validator’s error message.
- get_threshold()
- Returns:
password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.
- haystacks = []
A list of strings.
ConsecutiveCountValidator
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 = '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:
BaseSimilarityValidatorValidates that a given password is not based on a dictionary word.
Note
If
dictionaryANDwordsare 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 = 'invalid_dictionary_word'
The validator’s error code.
- message = 'The new password is based on a dictionary word.'
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_threshold()
- Returns:
password_policies.conf.Settings.PASSWORD_MATCH_THRESHOLD.
- haystacks = []
A list of strings.
EntropyValidator
- class password_policies.forms.validators.EntropyValidator
Validates that a password contains varied characters by calculating the Shannon entropy of a password.
- code = '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 = 'The new password is not varied enough.'
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:
BaseRFC4013ValidatorValidates that a given password does not contain invalid unicode characters as defined in RFC 4013, section 2.3.
- code = 'invalid_unicode'
The validator’s error code.
- message = 'The new password contains invalid unicode characters.'
The validator’s error message.
LetterCountValidator
- class password_policies.forms.validators.LetterCountValidator
Bases:
BaseCountValidatorCounts the occurrences of letters and raises a
ValidationErrorif the count is less thanget_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 = '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
NumberCountValidator
- class password_policies.forms.validators.NumberCountValidator
Bases:
BaseCountValidatorCounts the occurrences of numbers (digits, etc.) and raises a
ValidationErrorif the count is less thanget_min_count().- categories = ['Nd', 'No']
The unicode data number categories:
Code
Description
Nd
Number, Decimal Digit
No
Number, Other
- code = '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:
BaseCountValidatorCounts the occurrences of other characters than letters and numbers, except line breaks, and raises a
ValidationErrorif the count is less thanget_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 = '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
BidirectionalValidatorinstance.
validate_common_sequences
- password_policies.forms.validators.validate_common_sequences
A
CommonSequenceValidatorinstance.
validate_consecutive_count
- password_policies.forms.validators.validate_consecutive_count
A
ConsecutiveCountValidatorinstance.
validate_cracklib
- password_policies.forms.validators.validate_cracklib
A
CracklibValidatorinstance.
validate_dictionary_words
- password_policies.forms.validators.validate_dictionary_words
A
DictionaryValidatorinstance.
validate_entropy
- password_policies.forms.validators.validate_entropy
A
EntropyValidatorinstance.
validate_invalid_character
- password_policies.forms.validators.validate_invalid_character
A
InvalidCharacterValidatorinstance.
validate_letter_count
- password_policies.forms.validators.validate_letter_count
A
LetterCountValidatorinstance.
validate_not_email
- password_policies.forms.validators.validate_not_email
A
NotEmailValidatorinstance.
validate_number_count
- password_policies.forms.validators.validate_number_count
A
NumberCountValidatorinstance.
validate_symbol_count
- password_policies.forms.validators.validate_symbol_count
A
SymbolCountValidatorinstance.