perf;PasswordUtils校验调整
This commit is contained in:
@@ -2,7 +2,10 @@
|
|||||||
|
|
||||||
### 增加
|
### 增加
|
||||||
|
|
||||||
> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token;
|
> 1,TsTokenConfig增加新的属性**ignorePaths**,用于通过路径忽略token;
|
||||||
|
> 2,PasswordUtils增加密码复杂度校验方法;
|
||||||
|
> 3,PasswordUtils.verifyPassword增加登录次数限制:10分钟内不能错误6次;
|
||||||
|
>
|
||||||
|
|
||||||
### 调整
|
### 调整
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.tiesheng.util;
|
package com.tiesheng.util;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
@@ -21,6 +22,17 @@ public class PasswordUtils {
|
|||||||
return prefix + SecureUtil.sha1(password);
|
return prefix + SecureUtil.sha1(password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码复杂度校验
|
||||||
|
*
|
||||||
|
* @param userPassword
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean verifyComplexity(String userPassword) {
|
||||||
|
String password = "^(?![A-Za-z0-9]+$)(?![a-z0-9\\W]+$)(?![A-Za-z\\W]+$)(?![A-Z0-9\\W]+$)[a-zA-Z0-9\\W]{8,}$";
|
||||||
|
return userPassword.matches(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证密码
|
* 验证密码
|
||||||
@@ -30,12 +42,18 @@ public class PasswordUtils {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static void verifyPassword(String userInput, String encrypted) {
|
public static void verifyPassword(String userInput, String encrypted) {
|
||||||
|
String clientIp = ServletKit.getClientIP();
|
||||||
String userEncrypted = buildPassword(userInput);
|
String userEncrypted = buildPassword(userInput);
|
||||||
|
|
||||||
userEncrypted = StrUtil.subSuf(userEncrypted, PREFIX_SIZE);
|
userEncrypted = StrUtil.subSuf(userEncrypted, PREFIX_SIZE);
|
||||||
encrypted = StrUtil.subSuf(encrypted, PREFIX_SIZE);
|
encrypted = StrUtil.subSuf(encrypted, PREFIX_SIZE);
|
||||||
|
|
||||||
if (!StrUtil.equals(userEncrypted, encrypted)) {
|
if (!StrUtil.equals(userEncrypted, encrypted)) {
|
||||||
|
int num = NumberUtil.parseInt(TimedCacheHelper.getTimedCache().get(clientIp, false));
|
||||||
|
if (num > 5) {
|
||||||
|
throw new ApiException("登录失败已达6次,请10分钟后再试");
|
||||||
|
}
|
||||||
|
TimedCacheHelper.getTimedCache().put(clientIp, String.valueOf(num + 1), 10 * 60 * 1000);
|
||||||
throw new ApiException("账号或密码错误");
|
throw new ApiException("账号或密码错误");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,14 @@ public class ServletKit extends ServletUtil {
|
|||||||
return attributes.getRequest();
|
return attributes.getRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取客户端IP
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getClientIP() {
|
||||||
|
return getClientIP(getRequest());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user