LIVE_YE 9 달 전
부모
커밋
00ce0b9131

+ 9 - 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysUserController.java

@@ -249,4 +249,13 @@ public class SysUserController extends BaseController
     {
         return success(deptService.selectDeptTreeList(dept));
     }
+
+    /**
+     * 生成随机密码
+     */
+    @GetMapping("/sjmm")
+    public AjaxResult sjmm()
+    {
+        return userService.sjmm();
+    }
 }

+ 79 - 16
ruoyi-common/src/main/java/com/ruoyi/common/utils/PwdCheckUtil.java

@@ -1,5 +1,7 @@
 package com.ruoyi.common.utils;
 
+import java.util.Random;
+
 /**
  * @Author: tjf
  * @Date: 2022/10/10 9:24
@@ -10,19 +12,19 @@ public class PwdCheckUtil {
     public static String SPECIAL_CHAR = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
 
     /**
-     * @brief   检测密码中字符长度
+     * @return 符合长度要求 返回true
+     * @brief 检测密码中字符长度
      * @param[in] password            密码字符串
-     * @return  符合长度要求 返回true
      */
     public static boolean checkPasswordLength(String password, String minNum, String maxNum) {
-        boolean flag =false;
-        if (StringUtils.isBlank(maxNum))  {
-            minNum = StringUtils.isBlank(minNum) ? "0":minNum;
+        boolean flag = false;
+        if (StringUtils.isBlank(maxNum)) {
+            minNum = StringUtils.isBlank(minNum) ? "0" : minNum;
             if (password.length() >= Integer.parseInt(minNum)) {
                 flag = true;
             }
         } else {
-            minNum = StringUtils.isBlank(minNum) ? "0":minNum;
+            minNum = StringUtils.isBlank(minNum) ? "0" : minNum;
             if (password.length() >= Integer.parseInt(minNum) &&
                     password.length() <= Integer.parseInt(maxNum)) {
                 flag = true;
@@ -32,9 +34,9 @@ public class PwdCheckUtil {
     }
 
     /**
-     * @brief   检测密码中是否包含数字
+     * @return 包含数字 返回true
+     * @brief 检测密码中是否包含数字
      * @param[in] password            密码字符串
-     * @return  包含数字 返回true
      */
     public static boolean checkContainDigit(String password) {
         char[] chPass = password.toCharArray();
@@ -47,9 +49,9 @@ public class PwdCheckUtil {
     }
 
     /**
-     * @brief   检测密码中是否包含字母(不区分大小写)
+     * @return 包含字母 返回true
+     * @brief 检测密码中是否包含字母(不区分大小写)
      * @param[in] password            密码字符串
-     * @return  包含字母 返回true
      */
     public static boolean checkContainCase(String password) {
         char[] chPass = password.toCharArray();
@@ -63,9 +65,9 @@ public class PwdCheckUtil {
 
 
     /**
-     * @brief   检测密码中是否包含小写字母
+     * @return 包含小写字母 返回true
+     * @brief 检测密码中是否包含小写字母
      * @param[in] password            密码字符串
-     * @return  包含小写字母 返回true
      */
     public static boolean checkContainLowerCase(String password) {
         char[] chPass = password.toCharArray();
@@ -79,9 +81,9 @@ public class PwdCheckUtil {
 
 
     /**
-     * @brief   检测密码中是否包含大写字母
+     * @return 包含大写字母 返回true
+     * @brief 检测密码中是否包含大写字母
      * @param[in] password            密码字符串
-     * @return  包含大写字母 返回true
      */
     public static boolean checkContainUpperCase(String password) {
         char[] chPass = password.toCharArray();
@@ -95,9 +97,9 @@ public class PwdCheckUtil {
 
 
     /**
-     * @brief   检测密码中是否包含特殊符号
+     * @return 包含特殊符号 返回true
+     * @brief 检测密码中是否包含特殊符号
      * @param[in] password            密码字符串
-     * @return  包含特殊符号 返回true
      */
     public static boolean checkContainSpecialChar(String password) {
         char[] chPass = password.toCharArray();
@@ -108,4 +110,65 @@ public class PwdCheckUtil {
         }
         return false;
     }
+
+
+    /**
+     *
+     *   * 运行: java RandomStr 4  (生成长度为4的字符串)
+     *
+     */
+    public static void main(String[] args) {
+        int len = 8;
+        System.out.println(randomStr(len));
+    }
+
+    /**
+     * 返回随机字符串,同时包含数字、大小写字母
+     *
+     * @param len 字符串长度,不能小于3
+     * @return String 随机字符串
+     */
+    public static String randomStr(int len) {
+        if (len < 3) {
+            throw new IllegalArgumentException("字符串长度不能小于3");
+        }
+        Random random = new Random();
+        //数组,用于存放随机字符
+        char[] chArr = new char[len];
+        //为了保证必须包含数字、大小写字母
+        chArr[0] = (char) ('0' + StdRandom.uniform(0, 10));
+        chArr[1] = (char) ('A' + StdRandom.uniform(0, 26));
+        chArr[2] = (char) ('a' + StdRandom.uniform(0, 26));
+        //"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
+        char[] chars = {'@', '!', '%', '$', '*', '?', '&','.','|','#','+','-',':',';','='};
+        int index = random.nextInt(15);
+        chArr[3] = chars[index];
+
+
+
+        char[] codes = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
+                'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
+                'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
+                'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+                'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
+                'y', 'z','@', '!', '%', '$', '*', '?', '&','.','|','#','+','-',':',';','='};
+        //charArr[3..len-1]随机生成codes中的字符
+        for (int i = 4; i < len; i++) {
+            chArr[i] = codes[StdRandom.uniform(0, codes.length)];
+        }
+
+
+
+        //将数组chArr随机排序
+        for (int i = 0; i < len; i++) {
+            int r = i + StdRandom.uniform(len - i);
+            char temp = chArr[i];
+            chArr[i] = chArr[r];
+            chArr[r] = temp;
+        }
+
+        return new String(chArr);
+    }
+
 }

+ 90 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/StdRandom.java

@@ -0,0 +1,90 @@
+package com.ruoyi.common.utils;
+
+import java.util.Random;
+
+public class StdRandom {
+
+    //随机数生成器
+    private static Random random;
+    //种子值
+    private static long seed;
+
+    //静态代码块,初始化种子值及随机数生成器
+    static {
+        seed = System.currentTimeMillis();
+        random = new Random(seed);
+    }
+
+    //私有构造函数,禁止实例化
+    private StdRandom() {
+    }
+
+    /**
+     * 设置种子值
+     *
+     * @param s 随机数生成器的种子值
+     */
+    public static void setSeed(long s) {
+        seed = s;
+        random = new Random(seed);
+    }
+
+    /**
+     * 获取种子值
+     *
+     * @return long 随机数生成器的种子值
+     */
+    public static long getSeed() {
+        return seed;
+    }
+
+    /**
+     * 随机返回0到1之间的实数 [0,1)
+     *
+     * @return double 随机数
+     */
+    public static double uniform() {
+        return random.nextDouble();
+    }
+
+    /**
+     * 随机返回0到N-1之间的整数 [0,N)
+     *
+     * @param N 上限
+     * @return int 随机数
+     */
+    public static int uniform(int N) {
+        return random.nextInt(N);
+    }
+
+    /**
+     * 随机返回0到1之间的实数 [0,1)
+     *
+     * @return double 随机数
+     */
+    public static double random() {
+        return uniform();
+    }
+
+    /**
+     * 随机返回a到b-1之间的整数 [a,b)
+     *
+     * @param a 下限
+     * @param b 上限
+     * @return int 随机数
+     */
+    public static int uniform(int a, int b) {
+        return a + uniform(b - a);
+    }
+
+    /**
+     * 随机返回a到b之间的实数
+     *
+     * @param a 下限
+     * @param b 上限
+     * @return double 随机数
+     */
+    public static double uniform(double a, double b) {
+        return a + uniform() * (b - a);
+    }
+}

+ 1 - 1
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java

@@ -112,10 +112,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .authorizeRequests()
                 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                 .antMatchers("/login", "/register", "/captchaImage","/system/app/new").permitAll()
+                .antMatchers("/sendSms/**","/applet/**").permitAll()
                 // 静态资源,可匿名访问
                 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll()
                 .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()
-                .antMatchers("/sendSms/**","/applet/**").permitAll()
                 // 除上面外的所有请求全部需要鉴权认证
                 .anyRequest().authenticated()
                 .and()

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysUserService.java

@@ -1,6 +1,8 @@
 package com.ruoyi.system.service;
 
 import java.util.List;
+
+import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
 
 /**
@@ -212,4 +214,6 @@ public interface ISysUserService
      * @return 结果
      */
     public String importUser(List<SysUser> userList, Boolean isUpdateSupport, String operName);
+
+    AjaxResult sjmm();
 }

+ 19 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java

@@ -5,6 +5,8 @@ import java.util.List;
 import java.util.stream.Collectors;
 import javax.validation.Validator;
 
+import com.ruoyi.common.core.domain.AjaxResult;
+import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.PwdCheckUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -582,4 +584,21 @@ public class SysUserServiceImpl implements ISysUserService
         }
         return successMsg.toString();
     }
+
+    @Override
+    public AjaxResult sjmm() {
+        List<SysUser> sysUsers = selectUserList(new SysUser());
+        for (SysUser sysUser : sysUsers) {
+            if(sysUser.getEmail().isEmpty()){
+                //生成铭文密码 密码必须包含数字、大小写字母、特殊符号且大于8位
+                String pw = PwdCheckUtil.randomStr(8);
+                sysUser.setPlaintext(pw);
+                sysUser.setPassword(SecurityUtils.encryptPassword(pw));
+                userMapper.updateUser(sysUser);
+            }
+        }
+        return AjaxResult.success("成功");
+    }
+
+
 }