In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
本篇内容介绍了"java如何实现注册登录系统"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1、创建菜单,注册,登录,退出
2、注册模块:
a) 通过键盘输入用户名,密码
b) 保存用户名密码到user.txt文件(包含用户名和密码)
c) 注册成功
3、登录模块
a) 通过键盘输入用户名和密码
b) 判断(超过三次提示过多错误,需要休眠30秒)
c) 登陆成功
import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOException;import java.util.Properties;import java.util.Scanner;class TestRegex{ public boolean isUser(String user) { String regex="[1-9][0-9]{4,9}"; boolean b=user.matches(regex); return b; } public boolean isMiMa(String mm) { String regex="\\w+(\\.*\\w)"; boolean b=mm.matches(regex); return b; }}public class MySQLregisterTest{ //1. 注册登录系统 //1. 创建菜单,注册,登录,退出 public static void MySQLmenu() { System.out.println("***************************"); System.out.println("*****MySQL注册登录系统*****"); System.out.println("**1.注册"); System.out.println("**2.登录"); System.out.println("**3.退出"); } //2. 注册模块: //a) 通过键盘输入用户名,密码 //b) 保存用户名密码到user.txt文件(包含用户名和密码) //c) 注册成功 public static void MySQLregister() throws IOException { TestRegex tr=new TestRegex(); File f=new File("user.txt"); Scanner sc=new Scanner(System.in); System.out.println("欢迎来到注册界面!"); System.out.println("请输入用户名!"); String s=sc.next(); boolean bu=tr.isUser(s); FileInputStream fis=new FileInputStream("user.txt"); Properties pro=new Properties(); pro.load(fis); String user=pro.getProperty("user"); String pass=pro.getProperty("pass"); if(bu==false&&user.equals(s)) { System.out.println("账号注册失败"); }else { FileOutputStream fos=new FileOutputStream(f,true); byte[] bye=new byte[512]; int len=0; fos.write(("user="+s+"\r\n").getBytes()); fos.flush(); fos.close(); fis.close(); System.out.println("注册成功"); } System.out.println("请输入密码!"); String st=sc.next(); boolean bm=tr.isMiMa(st); if(bm==false&&pass.equals(st)) { System.out.println("密码注册失败"); }else { FileOutputStream fos=new FileOutputStream(f,true); byte[] bye=new byte[512]; int len=0; fos.write(("pass="+st+"\r\n").getBytes()); fos.flush(); fos.close(); fis.close(); System.out.println("账号注册成功"); } } //3. 登录模块 //a) 通过键盘输入用户名和密码 public static boolean Login() throws IOException{ boolean flag=false; Scanner sc=new Scanner(System.in); System.out.println("请输入用户名:"); String s=sc.next(); FileInputStream fis=new FileInputStream("user.txt"); Properties pro=new Properties(); pro.load(fis); String user=pro.getProperty("user"); String pass=pro.getProperty("pass"); if(s.equals(user)) { System.out.println("请输入密码:"); } String ms=sc.next(); if(ms.equals(pass)) { System.out.println("登录成功"); flag=true; } return flag; } //b) 判断(超过三次提示过多错误,需要休眠30秒) //c) 登陆成功 public static void Oder() { int n = 1; abc: while (n
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.