jiangping
2025-04-21 ebb2c8d515ef3756fb6634814f824f5dd5dd22c4
代码初始化
已添加1个文件
已修改5个文件
169 ■■■■■ 文件已修改
admin/lianhelihua_admin/index.html 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
admin/src/components/common/Header.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
admin/src/components/system/user/OperaUserWindow.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
admin/src/components/system/user/ResetPwdWindow.vue 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/com/doumee/biz/system/impl/SystemUserBizImpl.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
server/src/main/java/com/doumee/core/utils/PwdCheckUtil.java 78 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
admin/lianhelihua_admin/index.html
@@ -1 +1 @@
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/lianhelihua_admin/icon.png"><title>联合利华事件上报系统</title><link href="/lianhelihua_admin/static/css/app.b20beb91.css" rel="preload" as="style"><link href="/lianhelihua_admin/static/css/chunk-vendors.d9e68312.css" rel="preload" as="style"><link href="/lianhelihua_admin/static/js/app.17e4dc64.js" rel="preload" as="script"><link href="/lianhelihua_admin/static/js/chunk-vendors.40d691b2.js" rel="preload" as="script"><link href="/lianhelihua_admin/static/css/chunk-vendors.d9e68312.css" rel="stylesheet"><link href="/lianhelihua_admin/static/css/app.b20beb91.css" rel="stylesheet"></head><body><div id="app"></div><script src="/lianhelihua_admin/static/js/chunk-vendors.40d691b2.js"></script><script src="/lianhelihua_admin/static/js/app.17e4dc64.js"></script></body></html>
<!DOCTYPE html><html lang=""><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" href="/lianhelihua_admin/icon.png"><title>联合利华事件上报系统</title><link href="/lianhelihua_admin/static/css/app.c56f0a7d.css" rel="preload" as="style"><link href="/lianhelihua_admin/static/css/chunk-vendors.d9e68312.css" rel="preload" as="style"><link href="/lianhelihua_admin/static/js/app.f5e3eac0.js" rel="preload" as="script"><link href="/lianhelihua_admin/static/js/chunk-vendors.174acd1e.js" rel="preload" as="script"><link href="/lianhelihua_admin/static/css/chunk-vendors.d9e68312.css" rel="stylesheet"><link href="/lianhelihua_admin/static/css/app.c56f0a7d.css" rel="stylesheet"></head><body><div id="app"></div><script src="/lianhelihua_admin/static/js/chunk-vendors.174acd1e.js"></script><script src="/lianhelihua_admin/static/js/app.f5e3eac0.js"></script></body></html>
admin/src/components/common/Header.vue
@@ -72,7 +72,8 @@
            { required: true, message: '请输入原始密码' }
          ],
          newPwd: [
            { required: true, message: '请输入新密码' }
            { required: true, message: '请输入密码', trigger: 'blur' },
            { validator: this.validatePassword, trigger: 'blur' },
          ],
          confirmPwd: [
            { required: true, message: '请再次输入新密码' }
@@ -110,6 +111,26 @@
        this.$refs.changePwdDataForm.resetFields()
      })
    },
    validatePassword(rule, value, callback) {
      if (!value) {
        callback(new Error('请输入密码'))
      } else {
        const lengthValid = /^.{6,20}$/.test(value)
        const hasLetter = /[a-zA-Z]/.test(value)
        const hasNumber = /[0-9]/.test(value)
        const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(value)
        const typesCount = [hasLetter, hasNumber, hasSpecial].filter(Boolean).length
        if (!lengthValid) {
          callback(new Error('密码长度需为6到20个字符'))
        } else if (typesCount < 2) {
          callback(new Error('密码需包含字母、数字及特殊字符中的至少两种'))
        } else {
          callback() // éªŒè¯é€šè¿‡
        }
      }
    },
    /**
     * ç¡®å®šä¿®æ”¹å¯†ç 
     */
admin/src/components/system/user/OperaUserWindow.vue
@@ -77,7 +77,8 @@
          { required: true, message: '请输入姓名' }
        ],
        password: [
          { required: true, message: '请输入密码' }
          { required: true, message: '请输入密码', trigger: 'blur' },
          { validator: this.validatePassword, trigger: 'blur' }
        ],
        avatar: [
          { required: true, message: '请选择用户头像' }
@@ -95,6 +96,26 @@
    }
  },
  methods: {
    validatePassword (rule, value, callback) {
      if (!value) {
        callback(new Error('请输入密码'))
      } else {
        const lengthValid = /^.{6,20}$/.test(value)
        const hasLetter = /[a-zA-Z]/.test(value)
        const hasNumber = /[0-9]/.test(value)
        const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(value)
        const typesCount = [hasLetter, hasNumber, hasSpecial].filter(Boolean).length
        if (!lengthValid) {
          callback(new Error('密码长度需为6到20个字符'))
        } else if (typesCount < 2) {
          callback(new Error('密码需包含字母、数字及特殊字符中的至少两种'))
        } else {
          callback() // éªŒè¯é€šè¿‡
        }
      }
    },
    /**
     * æ‰“开窗口
     *
admin/src/components/system/user/ResetPwdWindow.vue
@@ -31,12 +31,33 @@
      },
      rules: {
        password: [
          { required: true, message: '请输入密码' }
          { required: true, message: '请输入密码', trigger: 'blur' },
          { validator: this.validatePassword, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    validatePassword (rule, value, callback) {
      if (!value) {
        callback(new Error('请输入密码'))
      } else {
        const lengthValid = /^.{6,20}$/.test(value)
        const hasLetter = /[a-zA-Z]/.test(value)
        const hasNumber = /[0-9]/.test(value)
        const hasSpecial = /[!@#$%^&*(),.?":{}|<>]/.test(value)
        const typesCount = [hasLetter, hasNumber, hasSpecial].filter(Boolean).length
        if (!lengthValid) {
          callback(new Error('密码长度需为6到20个字符'))
        } else if (typesCount < 2) {
          callback(new Error('密码需包含字母、数字及特殊字符中的至少两种'))
        } else {
          callback() // éªŒè¯é€šè¿‡
        }
      }
    },
    /**
     * æ‰“开窗口
     *
server/src/main/java/com/doumee/biz/system/impl/SystemUserBizImpl.java
@@ -3,6 +3,7 @@
import com.doumee.biz.system.SystemUserBiz;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.utils.PwdCheckUtil;
import com.doumee.core.utils.Utils;
import com.doumee.dao.system.dto.CreateSystemUserDTO;
import com.doumee.dao.system.dto.CreateUserRoleDTO;
@@ -56,6 +57,12 @@
    @Override
    public void updatePwd(UpdatePwdDto dto) {
        if(StringUtils.isBlank(dto.getNewPwd())
                ||dto.getNewPwd().length()>20
                ||dto.getNewPwd().length()<6
                ||!PwdCheckUtil.checkPassword(dto.getNewPwd())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,密码复杂度不满足要求:6-20个字符,至少包含字母、数字及特殊字符2种");
        }
        SystemUser user = systemUserService.findById(dto.getUserId());
        if (user.getDeleted()) {
            throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "用户不存在或已被删除");
@@ -73,6 +80,12 @@
    @Override
    public void resetPwd(ResetSystemUserPwdDTO dto) {
        if(StringUtils.isBlank(dto.getPassword())
                ||dto.getPassword().length()>20
                ||dto.getPassword().length()<6
                ||!PwdCheckUtil.checkPassword(dto.getPassword())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,密码复杂度不满足要求:6-20个字符,至少包含字母、数字及特殊字符2种");
        }
        // æŸ¥è¯¢ç”¨æˆ·
        SystemUser systemUser = systemUserService.findById(dto.getId());
        if (systemUser == null || systemUser.getDeleted()) {
@@ -88,6 +101,12 @@
    @Override
    @Transactional
    public void create(CreateSystemUserDTO systemUser) {
        if(StringUtils.isBlank(systemUser.getPassword())
                ||systemUser.getPassword().length()>20
                ||systemUser.getPassword().length()<6
                ||!PwdCheckUtil.checkPassword(systemUser.getPassword())){
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "对不起,密码复杂度不满足要求:6-20个字符,至少包含字母、数字及特殊字符2种");
        }
        // éªŒè¯ç”¨æˆ·å
        SystemUser queryUserDto = new SystemUser();
        queryUserDto.setUsername(systemUser.getUsername());
@@ -106,6 +125,7 @@
                throw new BusinessException(ResponseStatus.DATA_EXISTS.getCode(), "工号已存在");
            }
        }
        // ç”Ÿæˆå¯†ç ç›
        String salt = RandomStringUtils.randomAlphabetic(6);
        // ç”Ÿæˆå¯†ç 
server/src/main/java/com/doumee/core/utils/PwdCheckUtil.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,78 @@
package com.doumee.core.utils;
import java.util.regex.Pattern;
/**
 * Java正则校验密码至少包含:字母数字特殊符号中的2种
 */
public class PwdCheckUtil {
    /**
     * å‡å®šè®¾ç½®å¯†ç æ—¶ï¼Œå¯†ç è§„则为:  å­—母、数字、特殊符号,至少匹配2种
     * åˆ™å¯†ç å¯èƒ½å‡ºçŽ°çš„æƒ…å†µæœ‰ï¼š
     * 1、数字+特殊符号
     * 2、字母+特殊符号
     * 3、字母+数字
     * 4、字母+数字+特殊符号
     * (组合与顺序无关)
     * è§£å†³æ€è·¯ï¼š
     * 1、遍历字符串的字符数组,查看是否包含目标特殊字符,若包含,则标记字符串
     * åŒ…含特殊字符,并替换当前特殊字符为''。
     * 2、判断剩下的字符组成的字符串,是否匹配以下情况
     * - çº¯å­—母
     * - çº¯æ•°å­—
     * - å­—母+数字
     * 3、字符串匹配规则
     * çº¯å­—母+包含特殊字符  ---- åŒ¹é…é€šè¿‡
     * çº¯æ•°å­—+包含特殊字符 ---- åŒ¹é…é€šè¿‡
     * å­—母+数字+包含个数字符 ---- åŒ¹é…é€šè¿‡
     */
    //特殊字符
    public static final String SPEC_CHARACTERS = " !\"#$%&'()*+,-./:;<=>?@\\]\\[^_`{|}~";
    // çº¯å­—母
    public static final String character = "[a-zA-Z]{1,}$";
    // çº¯æ•°å­—
    public static final String numberic = "[0-9]{1,}$";
    // å­—母和数字
    public static final String number_and_character = "((^[a-zA-Z]{1,}[0-9]{1,}[a-zA-Z0-9]*)+)" +
            "|((^[0-9]{1,}[a-zA-Z]{1,}[a-zA-Z0-9]*)+)$";
    // å­—母或数字
    public static final String number_or_character = "[a-zA-Z0-9]+$";
    // å­—母数字下划线
    public static final String ncw = "\\w+$";
    public static boolean checkPassword(String targetString) {
        String opStr = targetString;
        boolean isLegal = false;
        boolean hasSpecChar = false;
        char[] charArray = opStr.toCharArray();
        for (char c : charArray) {
            if (SPEC_CHARACTERS.contains(String.valueOf(c))) {
                hasSpecChar = true;
                // æ›¿æ¢æ­¤å­—符串
                opStr = opStr.replace(c, ' ');
            }
        }
        String excSpecCharStr = opStr.replace(" ", "");
        boolean isPureNum = Pattern.compile(numberic).matcher(excSpecCharStr).matches();
        boolean isPureChar = Pattern.compile(character).matcher(excSpecCharStr).matches();
        boolean isNumAndChar = Pattern.compile(number_and_character).matcher(excSpecCharStr).matches();
        isLegal = ((isPureNum && hasSpecChar)
                || (isPureChar && hasSpecChar) || isNumAndChar && hasSpecChar) || isNumAndChar;
        System.out.println("字符串:" + targetString + ",是否符合规则:" + isLegal);
        System.out.println("---------------");
        return isLegal;
    }
    public static void main(String[] args) {
        checkPassword("123456a");
//        checkPassword("41234123");
//        checkPassword("#$%^&&*(");
//        checkPassword("fasd$$");
//        checkPassword("41234%%%");
//        checkPassword("fasd41^(324");
//        checkPassword("fa413%^&*");
//        checkPassword("&%fa413%^&*");
    }
}