0%

登录错误时的次数限制

day12

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
for (int i=0;i<3;i++) {
System.out.println("请输入用户名:");
String username = sc.next();
boolean flag = contains(list, username);
if (!flag) {//集合中没有该用户名
System.out.println("用户名未注册,请先注册");
return;
}
System.out.println("请输入密码");
String password = sc.next();
while (true) {
String vericode = getVericode();
System.out.println(vericode);
System.out.println("请录入验证码:");
String againcode = sc.next();
if (vericode.equalsIgnoreCase(againcode)) {//验证码正确
System.out.println("验证码录入成功");
System.out.println("成功登录");
break;
} else {
System.out.println("请重新录入验证码:");
continue;
}
}
Student stuInfo = new Student(username, password, null, null);
boolean result=checkstuInfo(list,stuInfo);
if (result){
System.out.println("登录成功,可以使用你的学生管理系统了");
break;
}else {
System.out.println("登录失败,用户名或密码错误");
if (i==2){
System.out.println("当前账号"+username+"被锁定");
return;
}else{
System.out.println("用户名或密码错误,还剩下"+(2-i)+"次机会");
}
}
}