Java模拟登录逻辑。判断用户输入的账号,密码与注册时的是否一致,以及判断用户输入的验证码是否正确

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);
  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值