密码复杂度,修改了源代码的 account_service.py 文件,添加
了对密码中特殊字符和大小写字母的包含要求检查,并将密码的最低长度限制提升到 8 位以提高用户密码的安全性。 但与该版本EnglishPal中jsonify函数起冲突。Bug534-NingShushuang
parent
1295616d5b
commit
becd7e9d7d
|
@ -23,11 +23,39 @@ def signup():
|
||||||
#! 添加如下代码为了过滤注册时的非法字符
|
#! 添加如下代码为了过滤注册时的非法字符
|
||||||
warn = WarningMessage(username)
|
warn = WarningMessage(username)
|
||||||
if str(warn) != 'OK':
|
if str(warn) != 'OK':
|
||||||
return jsonify({'status': '3', 'warn': str(warn)})
|
return str(warn)
|
||||||
|
# return jsonify({'status': '3', 'warn': str(warn)})
|
||||||
|
|
||||||
available = check_username_availability(username)
|
available = check_username_availability(username)
|
||||||
if not available: # 用户名不可用
|
if not available: # 用户名不可用
|
||||||
return jsonify({'status': '0'})
|
flash('用户名 %s 已经被注册。' %(username))
|
||||||
|
return render_template('signup.html')
|
||||||
|
elif len(password.strip()) < 8: # 密码过短
|
||||||
|
return '密码少于8位。'
|
||||||
|
# return jsonify({'status': '0'})
|
||||||
|
|
||||||
|
has_specialchar = False
|
||||||
|
specialchar_list = ['+', '-', '*', '/', '_', '&', '%', ',']
|
||||||
|
for c in password.strip():
|
||||||
|
if c in specialchar_list:
|
||||||
|
has_specialchar = True
|
||||||
|
break
|
||||||
|
if not has_specialchar:
|
||||||
|
return '密码必须包含特殊字符'
|
||||||
|
|
||||||
|
has_upper_letter = False
|
||||||
|
has_lower_letter = False
|
||||||
|
for c in password.strip():
|
||||||
|
if c.isupper():
|
||||||
|
has_upper_letter = True
|
||||||
|
elif c.islower():
|
||||||
|
has_lower_letter = True
|
||||||
|
has_both_letter = has_upper_letter and has_lower_letter
|
||||||
|
if has_both_letter:
|
||||||
|
break
|
||||||
|
if not has_both_letter:
|
||||||
|
return '密码必须同时包含大写字母和小写字母'
|
||||||
|
|
||||||
else: # 添加账户信息
|
else: # 添加账户信息
|
||||||
add_user(username, password)
|
add_user(username, password)
|
||||||
verified = verify_user(username, password)
|
verified = verify_user(username, password)
|
||||||
|
|
Loading…
Reference in New Issue