Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

发现验证码验证服务KaptchaServiceImpl有可能60s生成相同的,导致验证失败 #160

Open
violetdream opened this issue Oct 16, 2019 · 0 comments

Comments

@violetdream
Copy link
Collaborator

如果60s内,大量用户校验验证码时,如生成了两个相同的Code,存入Redis,验证时会失败。
以下是测试代码
public class UserProviderApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context=SpringApplication.run(UserProviderApplication.class,args);
KaptchaServiceImpl kaptchaService= (KaptchaServiceImpl) context.getBean("kaptchaServiceImpl");
Map<String,Object> map=new HashMap<String,Object>();
KaptchaCodeRequest request=new KaptchaCodeRequest();
for(int i=0;i<2000;i++){
KaptchaCodeResponse response=kaptchaService.getKaptchaCode(new KaptchaCodeRequest());
if(map.get(response.getImageCode())==null){
map.put(response.getImageCode(),response);
}else{
System.out.println("60s内有重复的token生成 redis里有两份一样的code,response = " + response);
request.setUuid(response.getUuid());
request.setCode(response.getCode());
KaptchaCodeResponse validateResponse=kaptchaService.validateKaptchaCode(request);
System.out.println("validateResponse = " + validateResponse);
}
}
}
结果总有一两笔是重复的:
60s内有重复的token生成 redis里有两份一样的code,response = KaptchaCodeResponse(imageCode=dktv, uuid=5e884bee-136c-4621-b58c-17f1485c28a3)
2019-10-16 16:47:16.654 INFO 908 --- [ main] c.p.user.services.KaptchaServiceImpl : 请求的redisKey=kaptcha_uuid5e884bee-136c-4621-b58c-17f1485c28a3,请求的code=000000,从redis获得的code=dktv
validateResponse = KaptchaCodeResponse(imageCode=null, uuid=null)
60s内有重复的token生成 redis里有两份一样的code,response = KaptchaCodeResponse(imageCode=961m, uuid=495d00e6-a8b7-4148-9375-4940f6bed166)
2019-10-16 16:47:30.025 INFO 908 --- [ main] c.p.user.services.KaptchaServiceImpl : 请求的redisKey=kaptcha_uuid495d00e6-a8b7-4148-9375-4940f6bed166,请求的code=000000,从redis获得的code=961m
validateResponse = KaptchaCodeResponse(imageCode=null, uuid=null)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant