Compare commits
11 Commits
a5c7752f63
...
new/v1.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
873460901a | ||
|
|
491ae3ddd6 | ||
|
|
550855360c | ||
|
|
e64478b8ab | ||
|
|
7598710f54 | ||
|
|
88f9a67d0c | ||
|
|
a60d62f511 | ||
|
|
59b9f2ff0f | ||
|
|
be4a4f00d4 | ||
|
|
be17f5ca1d | ||
|
|
44d5ca6ee7 |
7
.claude/settings.local.json
Normal file
7
.claude/settings.local.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"permissions": {
|
||||
"allow": [
|
||||
"Edit"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -71,8 +71,6 @@ public class RechargeOrderController extends BaseController {
|
||||
@SaCheckPermission("cai:rechargeOrder:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<RechargeOrderAdminVo> list(RechargeOrderAdminVo bo, PageQuery pageQuery) {
|
||||
String string = identifierGenerator.nextId(null).toString();
|
||||
log.info("ID============{}",string);
|
||||
Page<RechargeOrderAdminVo> page = rechargeOrderService.pageAdmin(pageQuery,bo);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.ruoyi.cai.service.IpBlackService;
|
||||
import com.ruoyi.cai.service.IpRecordService;
|
||||
import com.ruoyi.cai.service.SmsVerifyService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import com.ruoyi.cai.util.PasswordUtil;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
@@ -70,6 +71,10 @@ public class AuthAppController {
|
||||
if(!mobile){
|
||||
return R.fail(600,"请输入正确的手机格式");
|
||||
}
|
||||
PasswordUtil.PasswordValidationResult result = PasswordUtil.validatePassword(caiUser.getPassword());
|
||||
if(!result.isValid()){
|
||||
return R.fail(600,result.getErrorMessage());
|
||||
}
|
||||
String token = caiLoginManager.register(caiUser);
|
||||
LoginVo vo = new LoginVo();
|
||||
vo.setToken(token);
|
||||
@@ -112,7 +117,7 @@ public class AuthAppController {
|
||||
|
||||
|
||||
@Deprecated
|
||||
@PostMapping("/register/code")
|
||||
// @PostMapping("/register/code")
|
||||
@Operation(summary = "获取注册验证码")
|
||||
@Log(title = "获取注册验证码", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
public R<Map<String,String>> registerCode(@Validated @RequestBody RegisterCode code){
|
||||
@@ -227,7 +232,7 @@ public class AuthAppController {
|
||||
|
||||
|
||||
|
||||
@PostMapping("/login")
|
||||
// @PostMapping("/login")
|
||||
@Operation(summary = "登陆")
|
||||
@Log(title = "登陆", businessType = BusinessType.OTHER, isSaveDb = false)
|
||||
public R<LoginVo> login(@Validated @RequestBody LoginCaiUser loginBody){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.web.controller.cai.app;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.dto.app.RankIdReq;
|
||||
import com.ruoyi.cai.dto.app.vo.anchor.AnchorStatusDTO;
|
||||
@@ -272,10 +273,12 @@ public class RankAppController {
|
||||
if(StringUtils.isEmpty(nickname)){
|
||||
return "*";
|
||||
}
|
||||
if(containsEmoji(nickname)){
|
||||
return "*密";
|
||||
}
|
||||
return "*"+nickname.substring(nickname.length()-1);
|
||||
char c = RandomUtil.randomChinese();
|
||||
return "*"+c;
|
||||
// if(containsEmoji(nickname)){
|
||||
// return "*密";
|
||||
// }
|
||||
// return "*"+nickname.substring(nickname.length()-1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -22,7 +22,7 @@ spring:
|
||||
# rewriteBatchedStatements=true 批处理优化 大幅提升批量插入更新删除性能(对数据库有性能损耗 使用批量操作应考虑性能问题)
|
||||
url: jdbc:mysql://124.222.254.188:4306/cai_v6?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&rewriteBatchedStatements=true
|
||||
username: root
|
||||
password: tyYrk487R4y7FENM
|
||||
password: Zl930329!
|
||||
# 从库数据源
|
||||
slave:
|
||||
lazy: true
|
||||
@@ -57,7 +57,7 @@ spring:
|
||||
# 数据库索引
|
||||
database: 12
|
||||
# 密码(如没有密码请注释掉)
|
||||
password: dsjakldbwja
|
||||
password: WggDVPbn4eLpoX7
|
||||
# 连接超时时间
|
||||
timeout: 15s
|
||||
# 是否开启ssl
|
||||
@@ -65,7 +65,7 @@ spring:
|
||||
rabbitmq:
|
||||
addresses: 124.222.254.188 #ip地址
|
||||
username: admin # 账号
|
||||
password: THnpGkdS # 密码
|
||||
password: WggDVPbn4eLpoX7 # 密码
|
||||
port: 5672
|
||||
virtual-host: /cai-dev
|
||||
|
||||
@@ -120,3 +120,9 @@ cai:
|
||||
proxy-host: 7693
|
||||
home-name: 知予
|
||||
coin-name: 知钻
|
||||
tencent:
|
||||
captcha:
|
||||
app-secret-key: wCmccPiqdW1C8V3t7GdAIYB3Z
|
||||
captcha-app-id: 189992647
|
||||
secret-id: IKID8EXQFxZ2NbjiZHqGZjjaHpEh7OgruoZB
|
||||
secret-key: a3NbjkgTBbzNrFcwRtDORpYezddhgeWc
|
||||
|
||||
@@ -43,6 +43,7 @@ public class UserInfo {
|
||||
private BigDecimal payIncomeRate;
|
||||
/**
|
||||
*/
|
||||
@Deprecated
|
||||
private BigDecimal pointRate;
|
||||
/**
|
||||
* 登录次数
|
||||
|
||||
@@ -34,7 +34,7 @@ public enum SystemConfigEnum {
|
||||
VIP_PRIVATE_PLUS("0", "开启VIP隐私模式增强模式",SystemConfigGroupEnum.SECURITY,new BooleanSystemConfigCheck()),
|
||||
OPEN_ANCHOR_CHAT_COUNT("1", "开启主播主动消息统计",SystemConfigGroupEnum.SECURITY,new BooleanSystemConfigCheck()),
|
||||
// 4-recordId拦截 5-recordId加强拦截 6-性别拦截 7-vip加强拦截
|
||||
IM_FILTER_PLUS("0", "IM拦截配置(勿动,开发配置)",SystemConfigGroupEnum.SECURITY),
|
||||
IM_FILTER_PLUS("4", "IM拦截配置(勿动,开发配置)",SystemConfigGroupEnum.SECURITY),
|
||||
OPEN_NOTICE("1", "是否开启告警",SystemConfigGroupEnum.SECURITY, new BooleanSystemConfigCheck()),
|
||||
PAY_ERROR_NUM_NOTICE("2", "连续调用支付失败N次,发起告警",SystemConfigGroupEnum.SECURITY, new NumberSystemConfigCheck()),
|
||||
PAY_NOTIFY_ERROR_NUM_NOTICE("5", "连续调用N次支付,但是依旧未支付成功,发起告警",SystemConfigGroupEnum.SECURITY, new NumberSystemConfigCheck()),
|
||||
@@ -64,6 +64,7 @@ public enum SystemConfigEnum {
|
||||
/**
|
||||
* 抽奖和积分
|
||||
*/
|
||||
DEFAULT_PAY_POINT_RATE("0", "分销上级充值的积分提成",SystemConfigGroupEnum.DRAW,new RateAllowZeroSystemConfigCheck()),
|
||||
OPEN_DRAW_WOMEN("1","是否开启女用户积分抽奖",SystemConfigGroupEnum.DRAW,new BooleanSystemConfigCheck()),
|
||||
OPEN_DRAW_MAN("1","是否开启男用户积分抽奖",SystemConfigGroupEnum.DRAW,new BooleanSystemConfigCheck()),
|
||||
WOMEN_DRAW_POINT("100","女用户抽奖分数",SystemConfigGroupEnum.DRAW,new NumberSystemConfigCheck()),
|
||||
@@ -143,7 +144,6 @@ public enum SystemConfigEnum {
|
||||
DEFAULT_GIFT_INCOME_RATE("0.07", "默认分销上级礼物提成",SystemConfigGroupEnum.BUSINESS,new RateSystemConfigCheck()),
|
||||
DEFAULT_GUARD_INCOME_RATE("0.07", "默认分销上级守护提成",SystemConfigGroupEnum.BUSINESS,new RateSystemConfigCheck()),
|
||||
DEFAULT_PAY_INCOME_RATE("0.3", "默认分销上级充值提成",SystemConfigGroupEnum.BUSINESS,new RateSystemConfigCheck()),
|
||||
DEFAULT_PAY_POINT_RATE("0.07", "默认分销上级充值的积分提成",SystemConfigGroupEnum.BUSINESS,new RateSystemConfigCheck()),
|
||||
PAY_INCOME_RATE("0", "分销上级充值提成(配置大于0数据后将强制使用该提成)",SystemConfigGroupEnum.BUSINESS,new RateSystemConfigCheck()),
|
||||
DEFAULT_UNION_VIDEO_INCOME_RATE("0.01", "默认工会视频提成",SystemConfigGroupEnum.BUSINESS, new RateSystemConfigCheck()),
|
||||
DEFAULT_UNION_ONE_INCOME_RATE("0.07", "默认工会一级提成",SystemConfigGroupEnum.BUSINESS, new RateSystemConfigCheck()),
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.ruoyi.cai.enums.systemconfig;
|
||||
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class RateAllowZeroSystemConfigCheck implements ISystemConfigCheck{
|
||||
@Override
|
||||
public SystemCheckResp check(String value) {
|
||||
if(StringUtils.isEmpty(value)){
|
||||
return SystemCheckResp.fail("该配置必填");
|
||||
}
|
||||
boolean b = NumberUtil.isDouble(value);
|
||||
if(!b){
|
||||
return SystemCheckResp.fail("请填写(0-1)之间的数字,两位小数点");
|
||||
}
|
||||
BigDecimal bigDecimal = new BigDecimal(value);
|
||||
boolean in = NumberUtil.isIn(bigDecimal, BigDecimal.ZERO, BigDecimal.ONE);
|
||||
if(!in){
|
||||
return SystemCheckResp.fail("请填写(0-1)之间的数字,两位小数点");
|
||||
}
|
||||
if(bigDecimal.scale() > 2){
|
||||
return SystemCheckResp.fail("小数点位数只能配置两位");
|
||||
}
|
||||
return SystemCheckResp.ok();
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
RateAllowZeroSystemConfigCheck check = new RateAllowZeroSystemConfigCheck();
|
||||
System.out.println(check.check("0.0").getMessage());
|
||||
System.out.println(check.check("1").getMessage());
|
||||
}
|
||||
}
|
||||
@@ -106,6 +106,7 @@ public class PointManager {
|
||||
if(checkPointIncr.isAllowPoint()){
|
||||
User user = userService.getById(userId);
|
||||
User inviteUser = userService.getById(inviteUserId);
|
||||
accountMapper.incrPoint(user.getId(), checkPointIncr.getGivePoint());
|
||||
PointChangeLog pointChangeLog = new PointChangeLog();
|
||||
pointChangeLog.setUserId(userId);
|
||||
pointChangeLog.setUsercode(user.getUsercode());
|
||||
@@ -122,6 +123,9 @@ public class PointManager {
|
||||
pointChangeLog.setTraceLinkType(PointChangeTraceTypeEnum.INVITE.getCode());
|
||||
pointChangeLog.setTraceId(traceId);
|
||||
pointChangeLogService.save(pointChangeLog);
|
||||
String redisKey = getRedisKey(user.getId());
|
||||
RAtomicLong atomicLong = redissonClient.getAtomicLong(redisKey);
|
||||
atomicLong.addAndGet(checkPointIncr.getGivePoint());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,6 +169,7 @@ public class PointManager {
|
||||
if(checkPointIncr.isAllowPoint()){ // 参与积分
|
||||
User user = userService.getById(userId);
|
||||
User inviteUser = userService.getById(inviteUserId);
|
||||
accountMapper.incrPoint(user.getId(), checkPointIncr.getGivePoint());
|
||||
PointChangeLog pointChangeLog = new PointChangeLog();
|
||||
pointChangeLog.setUserId(userId);
|
||||
pointChangeLog.setUsercode(user.getUsercode());
|
||||
@@ -181,6 +186,9 @@ public class PointManager {
|
||||
pointChangeLog.setTraceLinkType(PointChangeTraceTypeEnum.INVITE.getCode());
|
||||
pointChangeLog.setTraceId(traceId);
|
||||
pointChangeLogService.save(pointChangeLog);
|
||||
String redisKey = getRedisKey(user.getId());
|
||||
RAtomicLong atomicLong = redissonClient.getAtomicLong(redisKey);
|
||||
atomicLong.addAndGet(checkPointIncr.getGivePoint());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,4 +12,6 @@ import com.ruoyi.cai.domain.UserCodeGen;
|
||||
public interface UserCodeGenService extends IService<UserCodeGen> {
|
||||
|
||||
String getCodeGen();
|
||||
|
||||
String getCodeGenRandom();
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import com.ruoyi.cai.domain.*;
|
||||
import com.ruoyi.cai.dto.AddPointAdminDto;
|
||||
import com.ruoyi.cai.enums.ConsumeLogStatus;
|
||||
import com.ruoyi.cai.enums.PointLogType;
|
||||
import com.ruoyi.cai.enums.SystemConfigEnum;
|
||||
import com.ruoyi.cai.lottery.PointManager;
|
||||
import com.ruoyi.cai.manager.IdManager;
|
||||
import com.ruoyi.cai.manager.SystemConfigManager;
|
||||
import com.ruoyi.cai.mapper.AccountMapper;
|
||||
import com.ruoyi.cai.mapper.PointRecordLogMapper;
|
||||
import com.ruoyi.cai.service.*;
|
||||
@@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
@@ -39,6 +42,8 @@ public class PointRecordLogServiceImpl extends ServiceImpl<PointRecordLogMapper,
|
||||
@Resource
|
||||
private AccountMapper accountMapper;
|
||||
@Autowired
|
||||
private SystemConfigManager systemConfigManager;
|
||||
@Autowired
|
||||
private PointChangeLogService pointChangeLogService;
|
||||
@Autowired
|
||||
private PointManager pointManager;
|
||||
@@ -66,8 +71,8 @@ public class PointRecordLogServiceImpl extends ServiceImpl<PointRecordLogMapper,
|
||||
if(userInvite != null){
|
||||
User oneUser = userService.getById(userInvite.getInviteId());
|
||||
if(oneUser != null && oneUser.getStatus() == 0){
|
||||
UserInfo inviteUserInfo = userInfoService.getByUserId(userInvite.getInviteId());
|
||||
pointLog.setOneRate(inviteUserInfo.getPointRate());
|
||||
BigDecimal payPointRate = systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_PAY_POINT_RATE);
|
||||
pointLog.setOneRate(payPointRate);
|
||||
pointLog.setOneUserId(oneUser.getId());
|
||||
pointLog.setOneUsercode(oneUser.getUsercode());
|
||||
pointLog.setOnePhone(oneUser.getMobile());
|
||||
@@ -102,8 +107,8 @@ public class PointRecordLogServiceImpl extends ServiceImpl<PointRecordLogMapper,
|
||||
if(userInvite != null){
|
||||
User oneUser = userService.getById(userInvite.getInviteId());
|
||||
if(oneUser != null && oneUser.getStatus() == 0){
|
||||
UserInfo userInfo = userInfoService.getByUserId(userInvite.getUserId());
|
||||
pointLog.setOneRate(userInfo.getPointRate());
|
||||
BigDecimal payPointRate = systemConfigManager.getSystemConfigOfBigDecimal(SystemConfigEnum.DEFAULT_PAY_POINT_RATE);
|
||||
pointLog.setOneRate(payPointRate);
|
||||
pointLog.setOneUserId(oneUser.getId());
|
||||
pointLog.setOneUsercode(oneUser.getUsercode());
|
||||
pointLog.setOnePhone(oneUser.getMobile());
|
||||
@@ -138,7 +143,7 @@ public class PointRecordLogServiceImpl extends ServiceImpl<PointRecordLogMapper,
|
||||
if(!update){
|
||||
return;
|
||||
}
|
||||
if(pointRecordLog.getOneUserId() == null || pointRecordLog.getPoints() <= 0){
|
||||
if(pointRecordLog.getOneUserId() == null || pointRecordLog.getOnePoints() <= 0){
|
||||
return;
|
||||
}
|
||||
if(!pointRecordLog.getOneJoin()){
|
||||
|
||||
@@ -88,6 +88,7 @@ public class RechargeOrderServiceImpl extends ServiceImpl<RechargeOrderMapper,Re
|
||||
order.setRechargeId(goods.getId());
|
||||
order.setRechargeName(goods.getName());
|
||||
order.setRechargeCoin(goods.getAmount());
|
||||
order.setGivePoint(goods.getGivePoint());
|
||||
order.setRechargeType(AccountTypeEnum.COIN.getCode());
|
||||
order.setPrice(goods.getPrice());
|
||||
order.setOrderNo(OrderNoUtil.createOrderNo(OrderTypeEnum.RECHARGE_ORDER_SUB));
|
||||
|
||||
@@ -128,7 +128,7 @@ public class SmsVerifyServiceImpl extends ServiceImpl<SmsVerifyMapper,SmsVerify>
|
||||
smsVerify.setVerifyCode(code);
|
||||
smsVerify.setSendInterface("阿里云");
|
||||
smsVerify.setOperateIp(clientIP);
|
||||
smsVerify.setOverTime(LocalDateTime.now().plusMinutes(5));
|
||||
smsVerify.setOverTime(LocalDateTime.now().plusMinutes(8));
|
||||
this.save(smsVerify);
|
||||
// boolean boo = aliSmsKit.sendMessage(mobile, codeEnum.getAliTemplate(), code, true);
|
||||
boolean boo = DuanXinBaoSmsKit.sendMessage(mobile, code);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.UserCodeGen;
|
||||
import com.ruoyi.cai.mapper.UserCodeGenMapper;
|
||||
@@ -27,8 +26,16 @@ public class UserCodeGenServiceImpl extends ServiceImpl<UserCodeGenMapper, UserC
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
|
||||
@Override
|
||||
public String getCodeGen() {
|
||||
public String getCodeGen(){
|
||||
UserCodeGen gen = new UserCodeGen();
|
||||
this.save(gen);
|
||||
return gen.getId()+"";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCodeGenRandom() {
|
||||
// 使用数据库唯一索引保证不重复 + 随机生成
|
||||
for (int i = 0; i < MAX_RETRY_COUNT; i++) {
|
||||
// 生成随机用户号
|
||||
|
||||
@@ -136,6 +136,9 @@ public enum TrdPayTypeEnum {
|
||||
* Wsz6yTi6AG5X6Cxt5Zt6rXKGKXitsX5I
|
||||
*/
|
||||
V13("https://pp123.bghyvwk.cn","/mapi.php","/api.php","/api/pay/trd/notify/v13","success"),
|
||||
/**
|
||||
* https://efps.epaylinks.cn/open/index.html#/document.html?documentId=102&firstLevelId=10003&contentId=1097
|
||||
*/
|
||||
V14("https://efps.epaylinks.cn","/mapi.php","/api.php","/api/pay/trd/notify/v14","success"),
|
||||
/**
|
||||
* 下单网关:http://n5d4.damiepay.paysanguo.com/Pay_Index.html
|
||||
|
||||
157
ruoyi-cai/src/main/java/com/ruoyi/cai/util/PasswordUtil.java
Normal file
157
ruoyi-cai/src/main/java/com/ruoyi/cai/util/PasswordUtil.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package com.ruoyi.cai.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 密码安全校验工具类
|
||||
*
|
||||
* @author 77
|
||||
* @date 2025-01-15
|
||||
*/
|
||||
public class PasswordUtil {
|
||||
|
||||
/**
|
||||
* 密码最小长度
|
||||
*/
|
||||
private static final int MIN_PASSWORD_LENGTH = 8;
|
||||
|
||||
/**
|
||||
* 常见弱密码列表
|
||||
*/
|
||||
private static final Set<String> COMMON_WEAK_PASSWORDS = new HashSet<>(Arrays.asList(
|
||||
"123456",
|
||||
"12345678",
|
||||
"123456789",
|
||||
"password",
|
||||
"qwerty",
|
||||
"12345",
|
||||
"1234567",
|
||||
"1234567890",
|
||||
"111111",
|
||||
"000000",
|
||||
"888888",
|
||||
"666666",
|
||||
"A123456",
|
||||
"a123456",
|
||||
"123456a",
|
||||
"123456A",
|
||||
"123456ab",
|
||||
"123456AB",
|
||||
"Password123",
|
||||
"password123",
|
||||
"Qwerty123",
|
||||
"qwerty123",
|
||||
"Admin123",
|
||||
"admin123",
|
||||
"Abc123456",
|
||||
"abc123456"
|
||||
));
|
||||
|
||||
/**
|
||||
* 字母正则表达式(包含大小写)
|
||||
*/
|
||||
private static final Pattern LETTER_PATTERN = Pattern.compile("[a-zA-Z]");
|
||||
|
||||
/**
|
||||
* 数字正则表达式
|
||||
*/
|
||||
private static final Pattern DIGIT_PATTERN = Pattern.compile("[0-9]");
|
||||
|
||||
/**
|
||||
* 校验密码安全性
|
||||
*
|
||||
* @param password 用户输入的密码
|
||||
* @return 校验结果对象
|
||||
*/
|
||||
public static PasswordValidationResult validatePassword(String password) {
|
||||
PasswordValidationResult result = new PasswordValidationResult();
|
||||
|
||||
// 1. 检查是否为空
|
||||
if (password == null || password.isEmpty()) {
|
||||
result.setValid(false);
|
||||
result.setErrorMessage("密码不能为空");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 2. 检查长度
|
||||
if (password.length() < MIN_PASSWORD_LENGTH) {
|
||||
result.setValid(false);
|
||||
result.setErrorMessage("密码长度不能少于" + MIN_PASSWORD_LENGTH + "位");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 3. 检查是否包含字母
|
||||
if (!LETTER_PATTERN.matcher(password).find()) {
|
||||
result.setValid(false);
|
||||
result.setErrorMessage("密码必须包含字母");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 4. 检查是否包含数字
|
||||
if (!DIGIT_PATTERN.matcher(password).find()) {
|
||||
result.setValid(false);
|
||||
result.setErrorMessage("密码必须包含数字");
|
||||
return result;
|
||||
}
|
||||
|
||||
// 5. 检查是否为常见弱密码
|
||||
String lowerCasePassword = password.toLowerCase();
|
||||
for (String weakPassword : COMMON_WEAK_PASSWORDS) {
|
||||
if (lowerCasePassword.equals(weakPassword.toLowerCase())) {
|
||||
result.setValid(false);
|
||||
result.setErrorMessage("密码过于简单,请使用更复杂的密码");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// 校验通过
|
||||
result.setValid(true);
|
||||
result.setErrorMessage(null);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 快速校验密码(仅返回boolean,不提供详细错误信息)
|
||||
*
|
||||
* @param password 用户输入的密码
|
||||
* @return true-密码安全,false-密码不安全
|
||||
*/
|
||||
public static boolean isPasswordValid(String password) {
|
||||
return validatePassword(password).isValid();
|
||||
}
|
||||
|
||||
/**
|
||||
* 密码校验结果内部类
|
||||
*/
|
||||
public static class PasswordValidationResult {
|
||||
/**
|
||||
* 是否校验通过
|
||||
*/
|
||||
private boolean valid;
|
||||
|
||||
/**
|
||||
* 错误信息(校验失败时有值,校验成功时为null)
|
||||
*/
|
||||
private String errorMessage;
|
||||
|
||||
public boolean isValid() {
|
||||
return valid;
|
||||
}
|
||||
|
||||
public void setValid(boolean valid) {
|
||||
this.valid = valid;
|
||||
}
|
||||
|
||||
public String getErrorMessage() {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
public void setErrorMessage(String errorMessage) {
|
||||
this.errorMessage = errorMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user