|
@@ -1,6 +1,7 @@
|
|
|
package com.zhongshu.card.server.core.util;
|
|
package com.zhongshu.card.server.core.util;
|
|
|
|
|
|
|
|
import com.zhongshu.card.server.core.dataConfig.PasswordCheckConf;
|
|
import com.zhongshu.card.server.core.dataConfig.PasswordCheckConf;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
@@ -27,29 +28,27 @@ public class ValidateUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 验证是否有特殊支付
|
|
|
|
|
|
|
+ * 验证是否有特殊支付 (有一个就是true)
|
|
|
*
|
|
*
|
|
|
* @param str
|
|
* @param str
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static ValidateResult hasSpecial(String str) {
|
|
|
|
|
|
|
+ public static ValidateResult isContainsSpecial(String str) {
|
|
|
ValidateResult result = new ValidateResult();
|
|
ValidateResult result = new ValidateResult();
|
|
|
String validPattern = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?\\s]";
|
|
String validPattern = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?\\s]";
|
|
|
Pattern pattern = Pattern.compile(validPattern);
|
|
Pattern pattern = Pattern.compile(validPattern);
|
|
|
Matcher matcher = pattern.matcher(str);
|
|
Matcher matcher = pattern.matcher(str);
|
|
|
- result.setSuccess(!matcher.matches());
|
|
|
|
|
StringBuilder specialChars = new StringBuilder();
|
|
StringBuilder specialChars = new StringBuilder();
|
|
|
- if (result.isSuccess()) {
|
|
|
|
|
- while (matcher.find()) {
|
|
|
|
|
- specialChars.append(matcher.group());
|
|
|
|
|
- }
|
|
|
|
|
- result.setMsg("包含特殊支付:" + specialChars);
|
|
|
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
|
+ result.setSuccess(true);
|
|
|
|
|
+ specialChars.append(matcher.group());
|
|
|
}
|
|
}
|
|
|
|
|
+ result.setMsg(specialChars.toString());
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 是否包含汉字
|
|
|
|
|
|
|
+ * 是否包含汉字 (有一个就是true)
|
|
|
*
|
|
*
|
|
|
* @param str
|
|
* @param str
|
|
|
* @return
|
|
* @return
|
|
@@ -58,13 +57,39 @@ public class ValidateUtils {
|
|
|
ValidateResult result = new ValidateResult();
|
|
ValidateResult result = new ValidateResult();
|
|
|
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
|
Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
|
|
|
Matcher matcher = pattern.matcher(str);
|
|
Matcher matcher = pattern.matcher(str);
|
|
|
- result.setSuccess(!matcher.matches());
|
|
|
|
|
StringBuilder specialChars = new StringBuilder();
|
|
StringBuilder specialChars = new StringBuilder();
|
|
|
- if (result.isSuccess()) {
|
|
|
|
|
- while (matcher.find()) {
|
|
|
|
|
- specialChars.append(matcher.group());
|
|
|
|
|
|
|
+ while (matcher.find()) {
|
|
|
|
|
+ result.setSuccess(true);
|
|
|
|
|
+ specialChars.append(matcher.group());
|
|
|
|
|
+ }
|
|
|
|
|
+ result.setMsg(specialChars.toString());
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 验证密码是否符合要求
|
|
|
|
|
+ * @param passWord
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static ValidateResult validatePassWord(String passWord) {
|
|
|
|
|
+ ValidateResult result = new ValidateResult();
|
|
|
|
|
+ result.setSuccess(true);
|
|
|
|
|
+ if(StringUtils.isEmpty(passWord)) {
|
|
|
|
|
+ result.setSuccess(false);
|
|
|
|
|
+ result.setMsg("密码不能为空");
|
|
|
|
|
+ }else {
|
|
|
|
|
+ if(passWord.length() < Integer.parseInt(PasswordCheckConf.MIN_LENGTH)
|
|
|
|
|
+ || passWord.length() > Integer.parseInt(PasswordCheckConf.MAX_LENGTH)) {
|
|
|
|
|
+ result.setSuccess(false);
|
|
|
|
|
+ result.setMsg(String.format("密码长度必须大于%s位,小于%s位", PasswordCheckConf.MIN_LENGTH, PasswordCheckConf.MAX_LENGTH));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (result.isSuccess()) {
|
|
|
|
|
+ ValidateResult validateResult = isContainsChinese(passWord);
|
|
|
|
|
+ if (validateResult.isSuccess()) {
|
|
|
|
|
+ result.setSuccess(false);
|
|
|
|
|
+ result.setMsg(String.format("密码不能包含汉字:%s", validateResult.getMsg()));
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- result.setMsg("包含汉字:" + specialChars);
|
|
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|