0841b1a103
- 前端:Vue3 + TS + Element Plus,24 个页面路由(课件/组题/教案/动画/思维导图/作文批改/命题/课堂/资源/社区等) - 后端:FastAPI + SQLAlchemy + SQLite,17 个路由模块,AI 服务层含降级模板 - AI:glm-5.x 推理模型已禁用思维链,确保输出真实内容 - 修复:ai_service 两处请求体注入 enable_thinking/thinking disabled - 测试账号:13900999999 / test1234
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
"""密码强度校验策略:拒绝常见弱密码,要求字母+数字组合。"""
|
|
import re
|
|
|
|
WEAK_PATTERNS = [
|
|
"123456", "123456789", "password", "111111", "000000", "888888",
|
|
"abc123", "qwerty", "654321", "12345678", "1234567", "admin",
|
|
]
|
|
|
|
CONSECUTIVE = ["0123456789", "9876543210", "abcdef", "qwerty", "asdfgh"]
|
|
|
|
|
|
def validate_password_strength(password: str) -> str | None:
|
|
"""返回错误提示;通过则返回 None。要求至少 6 位且含字母与数字。"""
|
|
if not password or len(password) < 6:
|
|
return "密码至少需要 6 个字符"
|
|
low = password.lower()
|
|
if low in WEAK_PATTERNS:
|
|
return "密码过于简单,请使用更复杂的密码"
|
|
if any(seq in low for seq in CONSECUTIVE):
|
|
return "密码包含连续字符,请更换"
|
|
has_letter = bool(re.search(r"[a-zA-Z]", password))
|
|
has_digit = bool(re.search(r"\d", password))
|
|
if not has_letter:
|
|
return "密码必须包含字母"
|
|
if not has_digit:
|
|
return "密码必须包含数字"
|
|
return None
|