|
@@ -15,6 +15,7 @@ from common.enc import mpfun, sys_user_data, sys_user_role_data, sys_user_post_d
|
|
|
from common.db import db_czrz
|
|
|
from common.auth_user import *
|
|
|
import traceback
|
|
|
+import re
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
|
@@ -891,6 +892,55 @@ async def userlist(
|
|
|
db: Session = Depends(get_db),
|
|
|
body = Depends(remove_xss_json),
|
|
|
user_id: int = Depends(valid_access_token)):
|
|
|
+
|
|
|
+ # 判断是否密码是否至少12位且必须包含大小写字母和数字
|
|
|
+ def check_password_base(pwd):
|
|
|
+ zz_str = '^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{12,}$'
|
|
|
+ re1 = re.search(zz_str, pwd)
|
|
|
+ if not re1:
|
|
|
+ raise Exception('密码至少12位且必须包含大小写字母和数字')
|
|
|
+ else:
|
|
|
+ check_password_special(pwd)
|
|
|
+
|
|
|
+ # 判断是否密码包含易猜解字符
|
|
|
+ def check_password_special(pwd):
|
|
|
+ list_special = ['admin', 'root', 'crld', 'crland', 'test', 'hello', '147258', '147369', '258369']
|
|
|
+ x=len(list_special)-1
|
|
|
+ for pwd_special in list_special:
|
|
|
+ if pwd_special in pwd.lower():
|
|
|
+ raise Exception('密码不能包含易猜解字符:'+str(pwd_special))
|
|
|
+ else:
|
|
|
+ if pwd_special==list_special[x]:
|
|
|
+ check_password_adv(pwd)
|
|
|
+
|
|
|
+ # 判断是否是连续、重复以及易猜解
|
|
|
+ def check_password_adv(pwd):
|
|
|
+ str_all = '1234567890-=' \
|
|
|
+ '=-0987654321' \
|
|
|
+ '!@#$%^&*()_+' \
|
|
|
+ '+_)(*&^%$#@!' \
|
|
|
+ 'abcdefghijklmnopqrstuvwxyz' \
|
|
|
+ 'zyxwvutsrqponmlkjihgfedcba' \
|
|
|
+ 'qwertyuiopasdfghjklzxcvbnm' \
|
|
|
+ 'mnbvcxzlkjhgfdsapoiuytrewq' \
|
|
|
+ '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik,9ol.0p;/'
|
|
|
+ pwd_len=len(pwd)
|
|
|
+ x = -1
|
|
|
+ y = x+3
|
|
|
+ while y < pwd_len:
|
|
|
+ x+=1
|
|
|
+ y+=1
|
|
|
+ pwd_cut = pwd[x:y]
|
|
|
+ #print(pwd_cut)
|
|
|
+ if pwd_cut.lower() in str_all and len(pwd_cut) == 3: # 无论是大写还是小写都统统转换为小写,为了匹配大写
|
|
|
+ raise Exception('密码不能包含3位以上连续字符:'+str(pwd_cut))
|
|
|
+
|
|
|
+ elif len(pwd_cut) == 3 and pwd_cut[0].lower() == pwd_cut[1].lower() == pwd_cut[2].lower():
|
|
|
+ raise Exception('密码不能包含3位以上重复字符:'+str(pwd_cut))
|
|
|
+
|
|
|
+ else:
|
|
|
+ if y==pwd_len:
|
|
|
+ print('密码复杂度合格')
|
|
|
try:
|
|
|
|
|
|
user = user_id_get_user_info(db,user_id)
|
|
@@ -898,6 +948,14 @@ async def userlist(
|
|
|
return {"code": 500, "msg":"旧密码错误"}
|
|
|
|
|
|
if "newPassword" in body:
|
|
|
+ try:
|
|
|
+ check_password_base(body['newPassword'])
|
|
|
+ except Exception as e:
|
|
|
+ return {
|
|
|
+ 'code': 500,
|
|
|
+ 'msg': str(e)
|
|
|
+ }
|
|
|
+
|
|
|
user.password = mpfun.enc_data(body['newPassword'])
|
|
|
user.sign = sys_user_data.get_sign_hmac(user)
|
|
|
user.update_by = user_id
|