Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Registration and Login system with java

Shulou Source: shulou.com Published: 2022-05-31 19:35:54 10月03日 Update

本篇内容介绍了"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

Tags: Password input login user name success system module account keyboard error hibernation content file more knowledge menu too much prompt login Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft Docker OPPO Reno Linux