手机号验证码登录,验证码输入错误次数超5次封禁
@Overridepublic boolean checkCaptcha(String phoneNum, String captcha) {String codeNum = (String) redisTemplate.opsForValue().get(UserCacheNames.USER_CAPTCHA + phoneNum);if (codeNum == null) {throw new WangyaoBusinessException("验证码已过期!请重新发送");}if(RedisUtil.hasKey(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum)){Integer errorCou = (Integer) redisTemplate.opsForValue().get(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum);if(errorCou>5){throw new WangyaoBusinessException("验证码错误次数过多,封禁中请1小时后再试!");}}if (!captcha.equals(codeNum)) {// 验证码错误 做错误次数限制 封禁1小时if (!RedisUtil.hasKey(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum)) {redisTemplate.opsForValue().set(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum, 1, 3600, TimeUnit.SECONDS);} else {Integer errorCount = (Integer) redisTemplate.opsForValue().get(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum);if(errorCount>5){redisTemplate.opsForValue().set(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum, errorCount+1);}else {throw new WangyaoBusinessException("验证码错误次数过多,请稍1小时后再试!");}}throw new WangyaoBusinessException("请输入正确验证码!");}else {RedisUtil.del(UserCacheNames.USER_CAPTCHA_ERROR_COUNT + phoneNum);}return true;}
效果