wangwei 6 년 전
부모
커밋
8be290ecb4
1개의 변경된 파일12개의 추가작업 그리고 7개의 파일을 삭제
  1. 12 7
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

+ 12 - 7
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -93,6 +93,7 @@ public class AuthServiceImpl implements AuthService {
 		String accountType = loginInfo.getAccountType();
 		String accountValue = loginInfo.getAccountValue();
 		String password = loginInfo.getPassword();
+		String clientIp = loginInfo.getClientIp();
 
 		if (StringUtils.isBlank(accountType)) {
 			throw new StatusException("B-001201", "accountType is null");
@@ -110,7 +111,7 @@ public class AuthServiceImpl implements AuthService {
 			throw new StatusException("B-001204", "accountType is wrong");
 		}
 
-		if (limited(accountType, accountValue)) {
+		if (limited(accountType, accountValue, clientIp)) {
 			throw new StatusException("B-001205", "密码重试次数已达到上限,请1分钟后重试");
 		}
 
@@ -161,7 +162,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			String rightPassword = userEntity.getPassword();
 			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountType, accountValue);
+				whenPasswordError(accountType, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 			user.setUserId(userEntity.getId());
@@ -190,7 +191,7 @@ public class AuthServiceImpl implements AuthService {
 			}
 			String rightPassword = student.getPassword();
 			if (!rightPassword.equals(password)) {
-				whenPasswordError(accountType, accountValue);
+				whenPasswordError(accountType, accountValue, clientIp);
 				throw new StatusException("B-001003", "账号或密码错误");
 			}
 
@@ -237,9 +238,11 @@ public class AuthServiceImpl implements AuthService {
 	 * @author WANGWEI
 	 * @param accountType
 	 * @param accountValue
+	 * @param ip
 	 */
-	private void whenPasswordError(String accountType, String accountValue) {
-		String key = "$_PW_ERR_" + accountType + "_" + accountValue;
+	private void whenPasswordError(String accountType, String accountValue, String ip) {
+		String key = new StringBuilder("$_PW_ERR_").append(accountType).append("_")
+				.append(accountValue).append("_").append(ip).toString();
 
 		Integer times = redisClient.get(key, Integer.class);
 		if (null != times) {
@@ -257,10 +260,12 @@ public class AuthServiceImpl implements AuthService {
 	 * @author WANGWEI
 	 * @param accountType
 	 * @param accountValue
+	 * @param ip
 	 * @return
 	 */
-	private boolean limited(String accountType, String accountValue) {
-		String key = "$_PW_ERR_" + accountType + "_" + accountValue;
+	private boolean limited(String accountType, String accountValue, String ip) {
+		String key = new StringBuilder("$_PW_ERR_").append(accountType).append("_")
+				.append(accountValue).append("_").append(ip).toString();
 
 		Integer times = redisClient.get(key, Integer.class);