Commit 39b1973c authored by 技术部-任文超's avatar 技术部-任文超

消除验证码错误记次冗余方法(测试环境即存在,未测出来)应是5次失效,实际是3次失效,现统一为3次失效

parent 92205ca3
......@@ -36,7 +36,7 @@ public interface Constants {
String REDIS_VERIFICATION_COUNT = "verification_code_count:";
Long Image_Need_Count = 3L;
Long IMAGE_FINITE_COUNT = 3L;
Long VERIFICATION_CODE_FINITE_COUNT = 3L;
String X_AUTH_TOKEN = "x-auth-token";
String ONE_TIME_TOKEN = "oneTimeToken";
......
......@@ -296,53 +296,10 @@ public class UserController implements IBaseController {
result.put("fail", JsonResult.buildErrorStateResult("登录失败", null));
return result;
}
// 校验短信密码
validateFastLoginVerificationCode(result, phoneNo, verificationCode);
result.put("success", JsonResult.buildSuccessResult(verificationCode, phoneNo));
return result;
}
/**
* 短信密码校验
* @param result - Map
* @param phoneNo - 登录手机号
* @param verificationCode - 短信密码
*/
private void validateFastLoginVerificationCode(Map<String, JsonResult> result, String phoneNo, String verificationCode) {
if (smsService.validateFastLoginVerificationCode(phoneNo, verificationCode)) {
return;
}
// 短信密码错误时,给该账号添加计数器
countErrorForPhoneNo(result, phoneNo, verificationCode);
}
/**
* 短信密码错误时,给该账号添加计数器
* @param result Map
* @param phoneNo 登录手机号
* @param verificationCode 短信密码
*/
private void countErrorForPhoneNo(Map<String, JsonResult> result, String phoneNo, String verificationCode) {
String passwordErrorCountKey = Constants.REDIS_PASSWORD_ERROR_COUNT + phoneNo;
if (!stringRedisTemplate.hasKey(passwordErrorCountKey)) {
stringRedisTemplate.opsForValue().set(passwordErrorCountKey, String.valueOf(0), Constants.ONE_DAY, TimeUnit.SECONDS);
}
LOGGER.info("用户快速登录,验证码校验失败,phoneNo:{} , verificationCode:{}", phoneNo, verificationCode);
// 密码错误计数
Long errorCount = stringRedisTemplate.opsForValue().increment(passwordErrorCountKey, 1L);
if(errorCount >= Constants.Image_Need_Count){
// 短信密码错误次数超过上限,执行销毁
String verificationCodeKey = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
stringRedisTemplate.delete(verificationCodeKey);
// 短信密码错误计数器归零
stringRedisTemplate.opsForValue().set(passwordErrorCountKey, String.valueOf(0));
stringRedisTemplate.expire(passwordErrorCountKey, Constants.ONE_DAY, TimeUnit.SECONDS);
result.put("fail", JsonResult.buildErrorStateResult("错误次数过多,请重新获取短信验证码", null));
}else{
result.put("fail", JsonResult.buildErrorStateResult("验证码不正确", null));
}
}
/**
* 用户快速注册
*
......@@ -752,6 +709,8 @@ public class UserController implements IBaseController {
if(needRetSendCode(phoneNo)){
String key = Constants.REDIS_PREFIX_VERIFICATION_CODE + phoneNo;
stringRedisTemplate.delete(key);
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
stringRedisTemplate.opsForHash().delete(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT);
throw new VerificationCodeErrorException("验证码失效,请重新获取");
}
}
......@@ -764,7 +723,7 @@ public class UserController implements IBaseController {
private boolean needRetSendCode(String phoneNo) {
String verificationCountKey = Constants.REDIS_VERIFICATION_COUNT + phoneNo;
Long getVerificationCount = stringRedisTemplate.opsForHash().increment(verificationCountKey, Constants.REDIS_VERIFICATION_COUNT, 1);
return (getVerificationCount >= 5);
return (getVerificationCount >= Constants.VERIFICATION_CODE_FINITE_COUNT);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment