From b187030ccd1e5e244c94da8bf8b1d9c50f4f9e2a Mon Sep 17 00:00:00 2001
From: heheng <475597332@qq.com>
Date: Wed, 15 Apr 2026 10:52:50 +0800
Subject: [PATCH] 新增增加密码复杂度
---
expert-admin/src/main/java/com/gkhy/web/controller/system/SysUserController.java | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/expert-admin/src/main/java/com/gkhy/web/controller/system/SysUserController.java b/expert-admin/src/main/java/com/gkhy/web/controller/system/SysUserController.java
index 9791a27..d861389 100644
--- a/expert-admin/src/main/java/com/gkhy/web/controller/system/SysUserController.java
+++ b/expert-admin/src/main/java/com/gkhy/web/controller/system/SysUserController.java
@@ -1,21 +1,5 @@
package com.gkhy.web.controller.system;
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
import com.gkhy.common.annotation.Log;
import com.gkhy.common.core.controller.BaseController;
import com.gkhy.common.core.domain.AjaxResult;
@@ -31,6 +15,16 @@
import com.gkhy.system.service.ISysPostService;
import com.gkhy.system.service.ISysRoleService;
import com.gkhy.system.service.ISysUserService;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.stream.Collectors;
/**
* 用户信息
@@ -139,6 +133,10 @@
return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
}
user.setCreateBy(getUsername());
+ // 检查新密码复杂性
+ if (!isValidPassword(user.getPassword())) {
+ return error("新密码必须包含数字和字母,并且可以包含特殊符号,长度至少为8个字符");
+ }
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
return toAjax(userService.insertUser(user));
}
@@ -196,6 +194,10 @@
{
userService.checkUserAllowed(user);
userService.checkUserDataScope(user.getUserId());
+ // 检查新密码复杂性
+ if (!isValidPassword(user.getPassword())) {
+ return error("新密码必须包含数字和字母,并且可以包含特殊符号,长度至少为8个字符");
+ }
user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
user.setUpdateBy(getUsername());
return toAjax(userService.resetPwd(user));
@@ -253,4 +255,11 @@
{
return success(deptService.selectDeptTreeList(dept));
}
+
+ private static boolean isValidPassword(String password) {
+ // 正则表达式检查密码是否包含数字和字母,并且长度至少为8个字符
+ //String passwordPattern = "^(?=.*[0-9])(?=.*[a-zA-Z]).{8,}$";
+ String passwordPattern = "^(?=.*[0-9])(?=.*[a-zA-Z])[a-zA-Z0-9@#$%^&+=]{8,}$";
+ return password.matches(passwordPattern);
+ }
}
--
Gitblit v1.9.2