验证码改为6位数

This commit is contained in:
wuchunlei
2024-07-24 09:53:05 +08:00
parent d41a69f176
commit 01d4b80b56
3 changed files with 109 additions and 89 deletions

View File

@@ -204,11 +204,11 @@ public class MyUserController {
}
}
//生成随机位数
//生成随机位数
Random random = new Random();
String i = random.nextInt(99999) + "";
String i = random.nextInt(999999) + "";
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 5 - i.length(); j++) {
for (int j = 0; j < 6 - i.length(); j++) {
sb.append("0");
}
i = sb.toString() + i;
@@ -237,9 +237,14 @@ public class MyUserController {
return R.error(500,"验证码频率过高,请稍后再试!");
}
}
//生成随机位数
//生成随机位数
Random random = new Random();
String code = random.nextInt(99999) + "";
String code = random.nextInt(999999) + "";
StringBuffer sb = new StringBuffer();
for (int j = 0; j < 6 - code.length(); j++) {
sb.append("0");
}
code = sb.toString() + code;
String timeCode = code + "_"+System.currentTimeMillis();
//redis 缓存验证码
redisTemplate.opsForValue().set("RegistCode"+email,timeCode,5, TimeUnit.MINUTES);