一个提供密码强度验证器和表单字段的Django可重用应用程序
项目描述
Django Passwords
django-passwords是一个可重用应用程序,它提供了一个表单字段和验证器来检查密码的强度。
安装
您可以通过输入以下命令使用pip安装django-passwords:
pip install django-passwords
或者通过输入以下命令使用easy_install安装:
easy_install django-passwords
或者通过下载tar包并输入以下命令手动安装:
python setup.py install
兼容性
django-passwords与Django 1.3至1.9 RC1兼容。Pythons 2.7和3.4都受到支持。
设置
django-passwords添加了6个可选设置
- 可选
指定密码的最小长度
PASSWORD_MIN_LENGTH = 6 # Defaults to 6
指定密码的最大长度
PASSWORD_MAX_LENGTH = 120 # Defaults to None
指定词典的位置(每行一个单词的文件)
PASSWORD_DICTIONARY = "/usr/share/dict/words" # Defaults to None
指定模糊匹配必须多接近才能被认为是匹配
PASSWORD_MATCH_THRESHOLD = 0.9 # Defaults to 0.9, should be 0.0 - 1.0 where 1.0 means exactly the same.
指定要尝试匹配密码的常见序列列表
PASSWORD_COMMON_SEQUENCES = [] # Should be a list of strings, see passwords/validators.py for default
指定密码必须包含的字符集中各种集合的字符数
PASSWORD_COMPLEXITY = { # You can omit any or all of these for no limit for that particular set "UPPER": 1, # Uppercase "LOWER": 1, # Lowercase "LETTERS": 1, # Either uppercase or lowercase letters "DIGITS": 1, # Digits "SPECIAL": 1, # Not alphanumeric, space or punctuation character "WORDS": 1 # Words (alphanumeric sequences separated by a whitespace or punctuation character) }
使用方法
要使用表单字段,只需导入并使用它
from django import forms
from passwords.fields import PasswordField
class ExampleForm(forms.Form):
password = PasswordField(label="Password")
您可以在自己的字段上使用验证器
from django import forms
from passwords.validators import dictionary_words
field = forms.CharField(validators=[dictionary_words])
您还可以创建自定义验证器实例,以指定自己的字段特定配置,而不是使用全局配置
from django import forms
from passwords.validators import (
DictionaryValidator, LengthValidator, ComplexityValidator)
field = forms.CharField(validators=[
DictionaryValidator(words=['banned_word'], threshold=0.9),
LengthValidator(min_length=8),
ComplexityValidator(complexities=dict(
UPPER=1,
LOWER=1,
DIGITS=1
)),
])
项目详情
关闭
django-passwords-0.3.12.tar.gz 的散列值
算法 | 散列摘要 | |
---|---|---|
SHA256 | bc8c552940003c44e4f903e51223f3f62f2497c79fc208d1e6b079f105cfa4ac |
|
MD5 | 6ca251368b8ccabc072c6a0296f2a663 |
|
BLAKE2b-256 | 2ef3b9734ca5db6401e2dbf14ffd84609de8d79caed05a9bcf6e60fab86f9697 |