Skip to content

Commit 6b5789c

Browse files
committed
v6.5.3
1 parent 528059f commit 6b5789c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

bus-core/src/main/java/org/aoju/bus/core/lang/Validator.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,4 +1150,33 @@ public static <T extends CharSequence> T validateCarDrivingLicence(T value, Stri
11501150
return value;
11511151
}
11521152

1153+
/**
1154+
* 验证是否符合密码要求
1155+
*
1156+
* @param value 值
1157+
* @param weak 是否弱密码
1158+
* @return 否符合密码要求
1159+
*/
1160+
public static boolean isPassword(String value, boolean... weak) {
1161+
boolean result = false;
1162+
for (final boolean element : weak) {
1163+
result ^= element;
1164+
}
1165+
return result ? isMatchRegex(RegEx.PASSWORD_WEAK, value) : isMatchRegex(RegEx.PASSWORD_STRONG, value);
1166+
}
1167+
1168+
/**
1169+
* 验证是是否符合密码要求
1170+
*
1171+
* @param value 值
1172+
* @param errorMsg 验证错误的信息
1173+
* @param weak 是否弱密码
1174+
* @throws ValidateException 验证异常
1175+
*/
1176+
public static void validatePassword(String value, String errorMsg, boolean... weak) throws ValidateException {
1177+
if (false == isPassword(value, weak)) {
1178+
throw new ValidateException(errorMsg);
1179+
}
1180+
}
1181+
11531182
}

0 commit comments

Comments
 (0)