Skip to main content

Django ZXCVBN Password

Back-end and Front-end password validation with ZXCVBN.

A combination of pirandig’s django-zxcvbn and aj-may’s django-password-strength Django apps. It combines back-end and front-end validation with strength meter display.

License

Software licensed under ISC license.

Installation

pip install django-zxcvbn-password

Requirements

The JavaScript code of this application uses JQuery, but JQuery is not bundled with it. Please install it separately. You might also want to use Bootstrap.

Usage

# settings.py

INSTALLED_APPS = [
    ...
    'zxcvbn_password',
    ...
]

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
    {
        'NAME': 'zxcvbn_password.ZXCVBNValidator',
        'OPTIONS': {
            'min_score': 3,
            'user_attributes': ('username', 'email', 'first_name', 'last_name')
        }
    }
]
# forms.py

from django import forms
from zxcvbn_password.fields import PasswordField, PasswordConfirmationField

class RegisterForm(forms.Form):
    password1 = PasswordField()
    password2 = PasswordConfirmationField(confirm_with=password1)
# views.py

if form.is_valid():
    user = User.objects.create_user(
        username=...,
        password=form.cleaned_data['password1']
    )

By default, other inputs won’t be used to compute the score, but you can enforce it like this:

# forms.py

from django import forms
from zxcvbn_password import zxcbnn
from zxcvbn_password.fields import PasswordField, PasswordConfirmationField

class RegisterForm(forms.Form):
    password1 = PasswordField()
    password2 = PasswordConfirmationField(confirm_with=password1)

    def clean():
        password = self.cleaned_data.get('password1')
        other_field1 = ...
        other_field2 = ...

        if password:
            score = zxcvbn(password, [other_field1, other_field2])['score']
            # score is between 0 and 4
            # raise forms.ValidationError if needed

        return self.cleaned_data

Screen-shot

https://cloud.githubusercontent.com/assets/3999221/23079032/5ae1513a-f54b-11e6-9d66-90660ad5fb2d.png

Documentation

On ReadTheDocs

Development

To run all the tests: tox

Changelog

2.0.2 (2018-08-21)

Documented

  • Improve usage notes (7a1ed42). Related issues/PRs: #31.

Fixed

  • Fix call to super in PasswordConfirmationInput (fc551b8).

  • Improve password validator help text (c5d21a1). Related issues/PRs: #46.

  • Strength bar color go green only when superior to min score (9a44fd8). Related issues/PRs: #3.

Tests

  • Add django 1.11 tests (815aaef).

  • Add py37/pypy plus django 2.0 tests, remove py34 tests (05711cd).

2.0.1 (2017-02-17)

  • Fix call to super in PasswordStrengthInput.

2.0.0 (2017-02-17)

  • Drop Django 1.8 support in favor of AUTH_PASSWORD_VALIDATORS setting introduced in Django 1.9.

  • Update zxcvbn to more recent version (dwolfhub/zxcvbn-python on GitHub).

  • Update JavaScript code to latest version.

  • Remove all settings (they now go in AUTH_PASSWORD_VALIDATOR options).

  • Change license to ISC.

Thanks to Nick Stefan and Daniel Wolf.

1.1.0 (2016-10-18)

  • Cookiecutterize the project.

1.0.5 (2015-03-31)

  • I don’t remember.

1.0.3 (2015-03-12)

  • Switch README to rst.

  • Fix manifest rules.

1.0.2 (2015-03-12)

  • Change package name from django_zxcvbn_password to zxcvbn_password.

1.0.0 (2015-02-21)

  • Beta release on PyPI.

0.1.0 (2015-02-01)

  • Alpha release on PyPI.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-zxcvbn-password-2.0.2.tar.gz (418.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_zxcvbn_password-2.0.2-py2.py3-none-any.whl (407.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-zxcvbn-password-2.0.2.tar.gz.

File metadata

  • Download URL: django-zxcvbn-password-2.0.2.tar.gz
  • Upload date:
  • Size: 418.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for django-zxcvbn-password-2.0.2.tar.gz
Algorithm Hash digest
SHA256 53f65985d96210669135d4bf3a586a68a5f063549e0af324e2e52dcd032f2667
MD5 949f45254a685747fd83b8f8aa3aff78
BLAKE2b-256 8abc35118097b5f6db04893af4449b7eb0363390de14d10063fe81469dd8ddbb

See more details on using hashes here.

File details

Details for the file django_zxcvbn_password-2.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: django_zxcvbn_password-2.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 407.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.6.4

File hashes

Hashes for django_zxcvbn_password-2.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b5fe567791ef2e48856a384aa63b85545d0a8cf23fda2263e9d8ac7834686589
MD5 9566d5c2dcd275fd0f8ec4e7662ed919
BLAKE2b-256 378993dfaa3c325132093dac000141ac0ea90fb84224502923f9b1b290b425a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page