Explorar o código

update 密码规则

deason hai 1 ano
pai
achega
72dc41b26d

+ 15 - 4
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/UserController.java

@@ -11,6 +11,7 @@ import cn.com.qmth.examcloud.commons.util.SHA256;
 import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserDomain;
 import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserFormDomain;
 import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
+import cn.com.qmth.examcloud.core.basic.base.util.BaseUtil;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
 import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
 import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
@@ -535,6 +536,11 @@ public class UserController extends ControllerSupport {
 
         trim(userForm, true);
         userForm.setId(null);
+
+        if(!BaseUtil.checkPassword(userForm.getPassword())){
+            throw new StatusException("密码至少包含大写字母、小写字母、数字、特殊符号中的三种,且长度限制在6-10位!");
+        }
+
         Map<String, Object> ret = saveUser(userForm);
 
         ReportsUtil.report(new AdminOperateReport(accessUser.getRootOrgId(), accessUser.getUserId(), AdminOperateType.TYPE6.getDesc(), "用户ID:" + ret.get("userId")));
@@ -816,12 +822,17 @@ public class UserController extends ControllerSupport {
     public void updatePass(@RequestParam String password) {
         User accessUser = getAccessUser();
         Long userId = accessUser.getUserId();
-        if (password.length() < 6) {
-            throw new StatusException("150411", "密码长度至少6位");
+
+        // if (password.length() < 6) {
+        //     throw new StatusException("150411", "密码长度至少6位");
+        // }
+        if(!BaseUtil.checkPassword(password)){
+            throw new StatusException("密码至少包含大写字母、小写字母、数字、特殊符号中的三种,且长度限制在6-10位!");
         }
+
         UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
-        String realPassword = StringEscapeUtils.unescapeJavaScript(password);
-        byte[] bytes = SHA256.encode(user.getLoginName() + realPassword);
+        // String realPassword = StringEscapeUtils.unescapeJavaScript(password);
+        byte[] bytes = SHA256.encode(user.getLoginName() + password);
         String encodePassword = ByteUtil.toHexAscii(bytes);
         int ret = userRepo.updatePasswordById(userId, encodePassword);
         if (ret == 0) {

+ 16 - 0
examcloud-core-basic-base/src/main/java/cn/com/qmth/examcloud/core/basic/base/util/BaseUtil.java

@@ -2,4 +2,20 @@ package cn.com.qmth.examcloud.core.basic.base.util;
 
 public class BaseUtil {
 
+    /**
+     * 密码规则:至少包含大写字母、小写字母、数字、符号中的三种,密码长度限制在6-10位
+     */
+    public static final String reg = "^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\\W_]+$)(?![a-z0-9]+$)(?![a-z\\W_]+$)(?![0-9\\W_]+$)[a-zA-Z0-9\\W_]{6,10}$";
+
+    public static boolean checkPassword(String str) {
+        return check(str, reg);
+    }
+
+    public static boolean check(String str, String reg) {
+        if (str != null && str.matches(reg)) {
+            return true;
+        }
+        return false;
+    }
+
 }