可配置的密码校验库
Project description
PassRule
可配置的密码校验库,支持自定义校验规则。
安装
pip install passrule
使用方法
基本使用
from passrule import PasswordValidator
# 使用默认规则
validator = PasswordValidator()
is_valid, errors = validator.validate("MyPassword123!")
print(is_valid) # True
print(errors) # []
自定义规则
from passrule import PasswordValidator, ValidationRule
# 自定义规则
rule = ValidationRule(
min_length=6,
max_length=20,
require_digits=True,
require_uppercase=False,
require_lowercase=True,
require_special_chars=True,
special_chars="!@#$%"
)
validator = PasswordValidator(rule)
is_valid, errors = validator.validate("password123!")
密码生成
from passrule import PasswordGenerator, ValidationRule
# 使用默认规则生成密码
generator = PasswordGenerator()
password = generator.generate() # 生成8位密码
password = generator.generate(12) # 生成12位密码
# 使用自定义规则生成密码
rule = ValidationRule(
min_length=10,
require_uppercase=True,
require_digits=True,
require_special_chars=False
)
generator = PasswordGenerator(rule)
password = generator.generate()
# 排除容易混淆的字符
rule = ValidationRule(
min_length=12,
exclude_chars="0Oo1Il" # 排除0, O, o, 1, I, l
)
generator = PasswordGenerator(rule)
password = generator.generate()
校验规则
min_length: 最小长度(默认8)max_length: 最大长度(默认无限制)require_digits: 是否需要数字(默认True)require_uppercase: 是否需要大写字母(默认True)require_lowercase: 是否需要小写字母(默认True)require_special_chars: 是否需要特殊字符(默认True)special_chars: 允许的特殊字符(默认"!@#$%^&*()_+-=[]{}|;:,.<>?")exclude_chars: 排除的字符(默认为空)
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
passrule-0.1.2.tar.gz
(40.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file passrule-0.1.2.tar.gz.
File metadata
- Download URL: passrule-0.1.2.tar.gz
- Upload date:
- Size: 40.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85bfc223a1f4cc71527bd31df2376817177c8cb1615567b8cc97ae16bf7fbefd
|
|
| MD5 |
f4f0539048b06ac7db8cdafc06953ae2
|
|
| BLAKE2b-256 |
d55ae4dce678877fb86ad02c210bda7e56e3f6adbbcb34813efd49588a0f0d18
|
File details
Details for the file passrule-0.1.2-py3-none-any.whl.
File metadata
- Download URL: passrule-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb080d072711f481c8b44ca5f5872631c6139ec808d5636585f4161ec5546e7a
|
|
| MD5 |
436dc938e7445be189f533f54eba42f1
|
|
| BLAKE2b-256 |
b15b9b642520e9d498f0a27757e94b56af8ed3470ec3bb93b3e62af3bc68b0f2
|