v0.8.8测试
This commit is contained in:
@@ -47,6 +47,7 @@ class SecurityUtils:
|
||||
def validate_password_strength(password: str) -> tuple:
|
||||
"""
|
||||
验证密码强度
|
||||
要求:大小写字母、数字、特殊符号 至少包含其中3种
|
||||
返回: (是否有效, 错误信息)
|
||||
"""
|
||||
if len(password) < 6:
|
||||
@@ -54,13 +55,17 @@ class SecurityUtils:
|
||||
if len(password) > 20:
|
||||
return False, "密码长度不能超过20位"
|
||||
|
||||
# 检查是否包含至少一个数字
|
||||
if not any(c.isdigit() for c in password):
|
||||
return False, "密码必须包含至少一个数字"
|
||||
# 检查四种字符类型
|
||||
has_upper = any(c.isupper() for c in password) # 大写字母
|
||||
has_lower = any(c.islower() for c in password) # 小写字母
|
||||
has_digit = any(c.isdigit() for c in password) # 数字
|
||||
has_special = any(not c.isalnum() for c in password) # 特殊符号
|
||||
|
||||
# 检查是否包含至少一个字母
|
||||
if not any(c.isalpha() for c in password):
|
||||
return False, "密码必须包含至少一个字母"
|
||||
# 统计满足的字符类型数量
|
||||
char_types = sum([has_upper, has_lower, has_digit, has_special])
|
||||
|
||||
if char_types < 3:
|
||||
return False, "密码必须包含大写字母、小写字母、数字、特殊符号中的至少3种"
|
||||
|
||||
return True, ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user