修复漏洞
This commit is contained in:
1 parent
710e4cfb90
commit
bb0b8bd7ef
14 files changed
+777
-161
No files matched your search
+57
@@ -0,0 +1,57 @@
|
||||
package com.bsd.pjcloud.common.core.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
/**
|
||||
* 弱口令校验:禁止密码与手机号/用户名相同等低强度规则。
|
||||
*/
|
||||
public final class PasswordWeakCheckUtil {
|
||||
|
||||
private PasswordWeakCheckUtil() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param rawPassword 明文密码
|
||||
* @param phone 手机号(可空)
|
||||
* @param username 用户名(可空)
|
||||
* @return 不通过时的中文原因;通过返回 null
|
||||
*/
|
||||
public static String validate(String rawPassword, String phone, String username) {
|
||||
if (StrUtil.isBlank(rawPassword)) {
|
||||
return "密码不能为空";
|
||||
}
|
||||
String pwd = StrUtil.trim(rawPassword);
|
||||
String phoneTrim = StrUtil.trim(phone);
|
||||
String userTrim = StrUtil.trim(username);
|
||||
if (StrUtil.isNotBlank(phoneTrim) && pwd.equals(phoneTrim)) {
|
||||
return "密码不能与手机号相同";
|
||||
}
|
||||
if (StrUtil.isNotBlank(userTrim) && pwd.equalsIgnoreCase(userTrim)) {
|
||||
return "密码不能与用户名相同";
|
||||
}
|
||||
if (pwd.length() < 8) {
|
||||
return "密码长度不能少于8位";
|
||||
}
|
||||
boolean hasLetter = false;
|
||||
boolean hasDigit = false;
|
||||
for (int i = 0; i < pwd.length(); i++) {
|
||||
char c = pwd.charAt(i);
|
||||
if (Character.isLetter(c)) {
|
||||
hasLetter = true;
|
||||
} else if (Character.isDigit(c)) {
|
||||
hasDigit = true;
|
||||
}
|
||||
}
|
||||
if (!hasLetter || !hasDigit) {
|
||||
return "密码必须同时包含字母和数字";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void assertStrong(String rawPassword, String phone, String username) {
|
||||
String err = validate(rawPassword, phone, username);
|
||||
if (err != null) {
|
||||
throw new IllegalArgumentException(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
sys.user.update.passwordError=\u539F\u5BC6\u7801\u9519\u8BEF\uFF0C\u4FEE\u6539\u5931\u8D25
|
||||
sys.user.query.error=\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u5931\u8D25
|
||||
sys.user.import.succeed=\u7528\u6237\u5BFC\u5165\u6210\u529F\uFF0C\u9ED8\u8BA4\u5BC6\u7801\u4E3A\u624B\u673A\u53F7
|
||||
sys.user.import.succeed=\u7528\u6237\u5BFC\u5165\u6210\u529F\uFF0C\u9ED8\u8BA4\u5BC6\u7801\u89C1\u7CFB\u7EDF\u53C2\u6570USER_DEFAULT_PASSWORD
|
||||
sys.user.username.existing={0} \u7528\u6237\u540D\u5DF2\u5B58\u5728
|
||||
sys.user.phone.existing={0} \u624b\u673a\u53f7\u5df2\u5b58\u5728
|
||||
sys.user.userInfo.empty={0} \u7528\u6237\u4FE1\u606F\u4E3A\u7A7A
|
||||
|
||||
Reference in new issue
Block a user