java實(shí)現(xiàn)注冊(cè)登錄系統(tǒng)
本文實(shí)例為大家分享了java實(shí)現(xiàn)注冊(cè)登錄系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
1、創(chuàng)建菜單,注冊(cè),登錄,退出
2、注冊(cè)模塊:
a) 通過(guò)鍵盤(pán)輸入用戶(hù)名,密碼
b) 保存用戶(hù)名密碼到user.txt文件(包含用戶(hù)名和密碼)
c) 注冊(cè)成功
3、登錄模塊
a) 通過(guò)鍵盤(pán)輸入用戶(hù)名和密碼
b) 判斷(超過(guò)三次提示過(guò)多錯(cuò)誤,需要休眠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.?? ?注冊(cè)登錄系統(tǒng) ?? ?//1.?? ?創(chuàng)建菜單,注冊(cè),登錄,退出 ?? ?public static void MySQLmenu() { ?? ??? ?System.out.println("***************************"); ?? ??? ?System.out.println("*****MySQL注冊(cè)登錄系統(tǒng)*****"); ?? ??? ?System.out.println("**1.注冊(cè)"); ?? ??? ?System.out.println("**2.登錄"); ?? ??? ?System.out.println("**3.退出"); ?? ?} ?? ?//2.?? ?注冊(cè)模塊: ?? ?//a)?? ?通過(guò)鍵盤(pán)輸入用戶(hù)名,密碼 ?? ?//b)?? ?保存用戶(hù)名密碼到user.txt文件(包含用戶(hù)名和密碼) ?? ?//c)?? ?注冊(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("歡迎來(lái)到注冊(cè)界面!"); ?? ??? ?System.out.println("請(qǐng)輸入用戶(hù)名!"); ?? ??? ?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("賬號(hào)注冊(cè)失敗"); ?? ??? ?}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("注冊(cè)成功"); ?? ??? ?} ?? ??? ?System.out.println("請(qǐng)輸入密碼!"); ?? ??? ?String st=sc.next(); ?? ??? ?boolean bm=tr.isMiMa(st); ?? ??? ?if(bm==false&&pass.equals(st)) { ?? ??? ??? ?System.out.println("密碼注冊(cè)失敗"); ?? ??? ?}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("賬號(hào)注冊(cè)成功"); ?? ??? ?} ?? ?} ?? ?//3.?? ? 登錄模塊 ?? ?//a)?? ?通過(guò)鍵盤(pán)輸入用戶(hù)名和密碼 ?? ? ?? ?public static boolean Login() throws IOException{ ?? ??? ?boolean flag=false; ?? ??? ?Scanner sc=new Scanner(System.in); ?? ??? ?System.out.println("請(qǐng)輸入用戶(hù)名:"); ?? ??? ?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("請(qǐng)輸入密碼:"); ?? ??? ?} ?? ??? ?String ms=sc.next(); ?? ??? ?if(ms.equals(pass)) { ?? ??? ??? ?System.out.println("登錄成功"); ?? ??? ??? ?flag=true; ?? ??? ?} ?? ??? ?return flag; ?? ?} ?? ?//b)?? ?判斷(超過(guò)三次提示過(guò)多錯(cuò)誤,需要休眠30秒) ?? ?//c)?? ?登陸成功 ?? ?public static void Oder() { ?? ??? ?int n = 1; ?? ??? ?abc: while (n <4) { ?? ??? ??? ?try { ?? ??? ??? ??? ?boolean flag = Login(); ?? ??? ??? ??? ?if (flag == false) { ?? ??? ??? ??? ??? ?n++; ?? ??? ??? ??? ?} else { ?? ??? ??? ??? ??? ?System.out.println("賬號(hào)或密碼錯(cuò)誤,請(qǐng)確認(rèn)賬號(hào)密碼"); ?? ??? ??? ??? ??? ?n = 4; ?? ??? ??? ??? ??? ?break abc; ?? ??? ??? ??? ?} ?? ??? ??? ?} catch (IOException e) { ?? ??? ??? ??? ?// TODO Auto-generated catch block ?? ??? ??? ??? ?e.printStackTrace(); ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?public static void main(String[] args) throws IOException, Exception { ?? ??? ?boolean flag=true; ?? ??? ?while(flag) { ?? ??? ??? ?MySQLmenu(); ?? ??? ??? ?Scanner sc=new Scanner(System.in); ?? ??? ??? ?System.out.println("請(qǐng)輸入選擇項(xiàng):"); ?? ??? ??? ?int n=sc.nextInt(); ?? ??? ??? ?switch(n) { ?? ??? ??? ?case 1: ?? ??? ??? ??? ?MySQLregister(); ?? ??? ??? ??? ?break; ?? ??? ??? ?case 2: ?? ??? ??? ??? ?Oder(); ?? ??? ??? ??? ?System.out.println("輸入次數(shù)達(dá)到上限,休眠30秒"); ?? ??? ??? ??? ?Thread.sleep(30000); ?? ??? ??? ??? ?break; ?? ??? ??? ?case 3: ?? ??? ??? ??? ?System.out.println("已退出系統(tǒng)"); ?? ??? ??? ??? ?flag=false; ?? ??? ??? ??? ?break; ?? ??? ??? ?default: ?? ??? ??? ??? ?System.out.println("輸入異常!請(qǐng)重新輸入"); ?? ??? ??? ?} ?? ??? ?} ?? ?} }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- java+mysql實(shí)現(xiàn)登錄和注冊(cè)功能
- Java實(shí)現(xiàn)登錄和注冊(cè)案例
- Java使用IO模擬注冊(cè)登錄
- Java基于IO流實(shí)現(xiàn)登錄和注冊(cè)功能
- Java實(shí)現(xiàn)登錄與注冊(cè)頁(yè)面
- javaweb實(shí)現(xiàn)注冊(cè)登錄頁(yè)面
- JavaWeb實(shí)現(xiàn)用戶(hù)登錄注冊(cè)功能實(shí)例代碼(基于Servlet+JSP+JavaBean模式)
- Java+mysql用戶(hù)注冊(cè)登錄功能
- JAVA簡(jiǎn)單實(shí)現(xiàn)MD5注冊(cè)登錄加密實(shí)例代碼
- Servlet+JavaBean+JSP打造Java Web注冊(cè)與登錄功能
相關(guān)文章
一文詳解如何使用線程池來(lái)優(yōu)化我們的應(yīng)用程序
線程池是一種工具,但并不是適用于所有場(chǎng)景。在使用線程池時(shí),我們需要根據(jù)應(yīng)用程序的性質(zhì)、計(jì)算資源的可用性和應(yīng)用程序的需求進(jìn)行適當(dāng)?shù)呐渲?。本文主要介紹了如何使用線程池來(lái)優(yōu)化我們的應(yīng)用程序,需要的可以參考一下2023-04-04java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人
這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)微信企業(yè)付款到個(gè)人功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-10-10java為什么使用BlockingQueue解決競(jìng)態(tài)條件問(wèn)題面試精講
這篇文章主要為大家介紹了java為什么使用BlockingQueue解決競(jìng)態(tài)條件問(wèn)題面試精講,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10Java數(shù)據(jù)結(jié)構(gòu)之鏈表的增刪查改詳解
在這篇文章中,小編將帶大家了解一下Java數(shù)據(jù)結(jié)構(gòu)中鏈表的增刪查改(以下結(jié)果均在IDEA中編譯)希望在方便自己復(fù)習(xí)的同時(shí)也能幫助到大家2022-09-09