Java模拟登录逻辑。判断用户输入的账号,密码与注册时的是否一致,以及判断用户输入的验证码是否正确
String account = "abc123";
String password = "a123";
Scanner sc = new Scanner(System.in);
System.out.println("请输入用户名");
String inAccount = sc.next();
System.out.println("请输入密码");
String inPassword = sc.next();
String str1 = "ABCDEFGHIGKLMNOPQRSTUVWXYZ";
String str2 = "abcdefghijklmnopqrstuvwxyz";
String str3 = "0123456789";
String str = str1+str2+str3;
int length = str.length();
Random random = new Random();
int num1 = random.nextInt(length);
int num2 = random.nextInt(length);
int num3 = random.nextInt(length);
int num4 = random.nextInt(length);
char word1 = str.charAt(num1);
char word2 = str.charAt(num2);
char word3 = str.charAt(num3);
char word4 = str.charAt(num4);
String verificationCode = ""+word1+word2+word3+word4;
System.out.println(verificationCode);
System.out.println("请输入验证码");
String verificationCode1 = verificationCode.toUpperCase();
String verificationCode2 = verificationCode.toLowerCase();
String verCode = sc.next();
boolean same1 = inAccount.equals(account) && inPassword.equals(password);
boolean same2 = Code.toUpperCase().equals(verificationCode1)||Code.toLowerCase().equals(verificationCode2);
String loadSuccess = same1 && same2? "登录成功" : "账号密码或验证码错误";
System.out.println(loadSuccess);