A Django password validator using the Pwned Passwords API to check for compromised passwords.
Project description
Django Pwned
A collection of django password validators.
Compatibility
- Python: 3.6, 3.7, 3.8, 3.9, 3.10
- Django: 3.2, 4.0
Installation
pip install django-pwned
For translations to work, add django_pwned
to INSTALLED_APPS
.
TL;DR:
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django_pwned.validators.GitHubLikePasswordValidator"},
{"NAME": "django_pwned.validators.MinimumUniqueCharactersPasswordValidator"},
{"NAME": "django_pwned.validators.PwnedPasswordValidator"},
]
Validators
PwnedPasswordValidator(request_timeout=1.5)
This validator uses the Pwned Passwords API to check for compromised passwords.
Internally, this validator checks password with django's
CommonPasswordValidator
and if password was not in django's list,
uses Pwned API to check password. So you can remove CommonPasswordValidator
if you're using this validator.
AUTH_PASSWORD_VALIDATORS = [
# ...
# {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django_pwned.validators.PwnedPasswordValidator"},
# ...
]
You can set the API request timeout with the request_timeout
parameter (in seconds).
If for any reason (connection issues, timeout, ...) the request to Pwned API fails, this validator skips checking password.
GitHubLikePasswordValidator(min_length=8, safe_length=15)
Validates whether the password is at least:
- 8 characters long, if it includes a number and a lowercase letter, or
- 15 characters long with any combination of characters
Based on Github's documentation about creating a strong password.
You may want to disable Django's NumericPasswordValidator
and MinimumLengthValidator
if you want to use
GitHubLikePasswordValidator
.
The minimum number of characters can be customized with the min_length
parameter. The length at which we remove the restriction about
requiring both number and lowercase letter can be customized with the
safe_length
parameter.
MinimumUniqueCharactersPasswordValidator(min_unique_characters=4)
Validates whether the password contains at least 4 unique characters.
For example aaaaaaaaaabbbbbbccc
is an invalid password, but aAbB
is a valid password.
The minimum number of unique characters can be customized with the
min_unique_characters
parameter.
Development
- Create and activate a python virtualenv.
- Install development dependencies in your virtualenv:
pip install -e '.[dev]'
- Install pre-commit hooks:
pre-commit install
- Run tests with coverage:
py.test --cov
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-pwned-1.1.0.tar.gz
.
File metadata
- Download URL: django-pwned-1.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f939b456379096b674aff98592f12703c682929cd1b6f48404878e81722cdb7d |
|
MD5 | acb9989792ecca174a18896d991ef29a |
|
BLAKE2b-256 | b316b5b4ef20a2205cf157fef5ca8acf79d759abf06a26b3a9fdfdd3a68e4fca |
File details
Details for the file django_pwned-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: django_pwned-1.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad1296acab66fb1def999d3e1d84523b444958f1d6ff10d5da8be1825ea1c9be |
|
MD5 | 0b56cc86c19ee60d7b842e6e398cc0b2 |
|
BLAKE2b-256 | 46107fda7d9bc768f7fd7f2485a6e971cf10b88c7a0c070fda83e2f00be557b5 |