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/SysProfileController.java | 28 +++++++++++++++++++++++++---
1 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/expert-admin/src/main/java/com/gkhy/web/controller/system/SysProfileController.java b/expert-admin/src/main/java/com/gkhy/web/controller/system/SysProfileController.java
index c1f8d01..ea900b2 100644
--- a/expert-admin/src/main/java/com/gkhy/web/controller/system/SysProfileController.java
+++ b/expert-admin/src/main/java/com/gkhy/web/controller/system/SysProfileController.java
@@ -1,5 +1,9 @@
package com.gkhy.web.controller.system;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@@ -10,7 +14,7 @@
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.gkhy.common.annotation.Log;
-import com.gkhy.common.config.expertConfig;
+import com.gkhy.common.config.ExpertConfig;
import com.gkhy.common.core.controller.BaseController;
import com.gkhy.common.core.domain.AjaxResult;
import com.gkhy.common.core.domain.entity.SysUser;
@@ -30,6 +34,7 @@
*/
@RestController
@RequestMapping("/system/user/profile")
+@Api(tags = "基础信息修改")
public class SysProfileController extends BaseController
{
@Autowired
@@ -87,7 +92,12 @@
*/
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
@PutMapping("/updatePwd")
- public AjaxResult updatePwd(String oldPassword, String newPassword)
+ @ApiOperation(value = "修改密码")
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", name = "oldPassword", dataType = "String", required = true, value = "原密码"),
+ @ApiImplicitParam(paramType = "query", name = "newPassword", dataType = "String", required = true, value = "新密码")
+ })
+ public AjaxResult updatePwd(@RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword")String newPassword)
{
LoginUser loginUser = getLoginUser();
String userName = loginUser.getUsername();
@@ -100,6 +110,11 @@
{
return error("新密码不能与旧密码相同");
}
+ // 检查新密码复杂性
+ if (!isValidPassword(newPassword)) {
+ return error("新密码必须包含数字和字母,并且可以包含特殊符号,长度至少为8个字符");
+ }
+
newPassword = SecurityUtils.encryptPassword(newPassword);
if (userService.resetUserPwd(userName, newPassword) > 0)
{
@@ -111,6 +126,13 @@
return error("修改密码异常,请联系管理员");
}
+ // 添加密码复杂性检查方法
+ 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);
+ }
/**
* 头像上传
*/
@@ -121,7 +143,7 @@
if (!file.isEmpty())
{
LoginUser loginUser = getLoginUser();
- String avatar = FileUploadUtils.upload(expertConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
+ String avatar = FileUploadUtils.upload(ExpertConfig.getAvatarPath(), file, MimeTypeUtils.IMAGE_EXTENSION);
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
{
AjaxResult ajax = AjaxResult.success();
--
Gitblit v1.9.2