ludc
2023-03-26 c0f21a9745daa3afef19110025bdee9d0ba00338
Source/BladeX/blade-service/blade-user/src/main/java/org/springblade/system/user/service/impl/UserServiceImpl.java
@@ -293,7 +293,6 @@
   @Override
   public boolean updatePassword(Long userId, String oldPassword, String newPassword, String newPassword1) {
      String hex = DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes()));
      User user = getById(userId);
      if (!newPassword.equals(newPassword1)) {
         throw new ServiceException("请输入正确的确认密码!");
@@ -303,19 +302,37 @@
      }
      //获取用户采用的密码策略
      Strategy strategy = sysClient.getByUserId(userId).getData();
      String resException = "密码中必须含有【"+strategy.getCombinationIds()+"】中的【"+strategy.getRequiredType()+"】种密码组合方式,且密码长度必须在【"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"】范围内";
      //密码长度校验
      if(newPassword1.length() < strategy.getMinPwdLen() || newPassword1.length() > strategy.getMaxPwdLen()){
         throw new ServiceException("密码中必须含有【"+strategy.getCombinationNames()+"】中的【"+strategy.getRequiredType()+"】种密码组合方式,且密码长度必须在【"+strategy.getMinPwdLen()+"-"+strategy.getMaxPwdLen()+"】范围内");
      }
      List<String> regexs = sysClient.getRegexByList(Arrays.asList(strategy.getCombinationIds().split(","))).getData();
      //判断是否满足组合方式中的必填种类数
      int reqType = 0;
      for (int i = 0; i < regexs.size(); i++) {
         if(reqType>=strategy.getRequiredType()){
            break;
         }
         if(!Func.isEmpty(RegexUtil.findResult(regexs.get(i),newPassword1))){
            reqType++;
         }
      }
      String resException = "密码中必须含有【"+strategy.getCombinationNames()+"】中的【"+strategy.getRequiredType()+"】种类型,请重新输入密码!";
      if(reqType<strategy.getRequiredType()){
         throw new ServiceException(resException);
      }
      //查询密码策略取值
      // 是否属于组合方式中的类型
      String regex = sysClient.getRegex(Arrays.asList(strategy.getCombinationIds().split(","))).getData();
      System.out.println("===============regex================"+regex);
      regex = "^"+regex+"$";
      String result = RegexUtil.findResult(regex, newPassword);
      System.out.println(result);
      return this.update(Wrappers.<User>update().lambda().set(User::getPassword, DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes()))).eq(User::getId, userId));
      //return true;
      regex = "^"+regex+"{"+strategy.getRequiredType()+",}$";
      boolean result = RegexUtil.find(regex, newPassword1);
      if(!result){
         throw new ServiceException(resException);
      }
      //修改密码同时,改变用户信息中的密码修改状态字段
      return this.update(Wrappers.<User>update().lambda()
         .set(User::getPassword, DigestUtil.hex(DigestUtils.md5DigestAsHex((newPassword1).getBytes())))
         .set(User::getStrategyUpdateStatus,CommonConstant.TOP_PARENT_ID)
         .eq(User::getId, userId));
   }
   @Override