Password Strength Checking in Python

I’ve recently uploaded a tool to check password strength in Python. Prior, it seems like the only options that existed were to call cracklib via ctypes or using django-passwords, which, obviously, only works in the context of Django.

I took django-passwords and modified it to work as a library. It works as four separate validation classes:

  • LengthValidator: Check if between minimum and maximum lengths.
  • ComplexityValidator: Check for a minimum of certain character classes.
  • DictionaryValidator: Check if a password exists within a predefined list.
  • CommonSequenceValidator: Check is a password is a alphabetic, numeric, etc.. sequence.

Example of usage:

# See example for more information.

from password_check import ComplexityValidator, ValidationError

complexity = { # A minimum of N upper-case letters.
               "UPPER": 2,
               
               # A minimum of N lower-case letters.
               "LOWER": 2,
               
               # A minimum of N digits.
               "DIGITS": 2,
              
               # A minimum of N punctuation characters.
               "PUNCTUATION": 2,

               # A minimum of N non-ASCII characters ("\xx")
               "NON ASCII": 0,

               # A minimum of N space-separated, unique words.
               "WORDS": 0 }

complexity_validator = ComplexityValidator(complexity)

# Throws ValidationError due to several violations.
complexity_validator('simplepassword')

For more examples, go to the link, above, and look at the example script.

Advertisements