优化代码变量定义

This commit is contained in:
2026-06-04 17:56:30 +08:00
parent c590b1b693
commit 2b74a83352
2 changed files with 6 additions and 1 deletions

View File

@@ -233,13 +233,15 @@ public class SysPasswdServiceImpl implements SysPasswdService, BaseParams {
if (StringUtils.isBlank(account)) { if (StringUtils.isBlank(account)) {
return; return;
} }
// 账号名占比限制
double ratioLimit = 0.5;
String lowerPassword = password.toLowerCase(); String lowerPassword = password.toLowerCase();
String lowerAccount = account.toLowerCase(); String lowerAccount = account.toLowerCase();
// 检查账号名是否出现在密码中 // 检查账号名是否出现在密码中
if (lowerPassword.contains(lowerAccount)) { if (lowerPassword.contains(lowerAccount)) {
// 计算账号名在密码中的占比 // 计算账号名在密码中的占比
double ratio = (double) account.length() / password.length(); double ratio = (double) account.length() / password.length();
if (ratio > 0.5) { if (ratio > ratioLimit) {
throw new BizWarning("账号名在密码中所占长度不能超过一半"); throw new BizWarning("账号名在密码中所占长度不能超过一半");
} }
} }

View File

@@ -48,8 +48,11 @@ import java.util.Objects;
public class SysUserPasswdRuleServiceImpl implements SysUserPasswdRuleService, BaseParams { public class SysUserPasswdRuleServiceImpl implements SysUserPasswdRuleService, BaseParams {
private final static AppCache CACHE_PARAM = AppCache.SYS_CACHE_AP_RULE; private final static AppCache CACHE_PARAM = AppCache.SYS_CACHE_AP_RULE;
private final SysUserPasswdRuleBaseService sysUserPasswdRuleBaseService; private final SysUserPasswdRuleBaseService sysUserPasswdRuleBaseService;
private final SysUserPasswdRuleConvert sysUserPasswdRuleConvert; private final SysUserPasswdRuleConvert sysUserPasswdRuleConvert;
@Resource @Resource
private RedisService redisService; private RedisService redisService;