package denglu;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import zhuce.ZhuCe;
public class DengLu {
public static int i = 0;
public static void main(String[] args) throws IOException {
System.out.println("=================欢迎使用我爱学习网===================");
Properties ptD = new Properties();
BufferedReader bw = new BufferedReader(new FileReader("a.txt"));
ptD.load(bw);
bw.close();
dengLuZhangH(ptD);
}
public static void dengLuZhangH(Properties ptD) {
ZhuCe z = new ZhuCe();
System.out.println("请输入用户账号:");
Scanner sc = new Scanner(System.in);
String strZ = sc.nextLine();
Set<String> set = ptD.stringPropertyNames();
if(set.contains(strZ)) {
dengLuMiM(ptD,strZ);
}
else{
System.out.println("用户账号不存在!");
i++;
if(i<2){
dengLuZhangH(ptD);
}
else{
System.out.println("没有账号,赶紧注册吧!");
z.zhangHao(ptD);
}
}
}
public static void dengLuMiM(Properties ptD,String strZ) {
System.out.println("请输入登录密码:");
Scanner sc = new Scanner(System.in);
String strM = sc.nextLine();
if(ptD.getProperty(strZ).equals(strM)){
System.out.println("登录成功!");
//目前登录成功后没有添加其他操作
}
else{
System.out.println("密码输入错误!");
dengLuMiM(ptD,strZ);
}
}
}
package zhuce;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
//注册我爱学习网,将注册信息存储到文件中,只有账号和密码
//账号:邮箱或手机号
//密码:6-12位数字或字母,0不能开头。
public class ZhuCe {
static String zhangH = null;
static String miM = null;
public static void main(String[] args) throws IOException {
Properties pt = new Properties();
Properties ptr = new Properties();
BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt",true));
BufferedReader br = new BufferedReader(new FileReader("a.txt"));
ptr.load(br);
br.close();
System.out.println("=====================欢迎注册我爱学习网===================");
zhangHao(ptr);
pt.setProperty(zhangH, miM);
pt.store(bw, "用户注册信息");
bw.close();
System.out.println("用户注册信息添加完毕!");
}
public static void zhangHao(Properties ptr) {
Set<String> set = ptr.stringPropertyNames();
System.out.println("请输入注册账号(手机号或邮箱):");
Scanner sc = new Scanner(System.in);
String str = sc.next();
String regex1 = "[1][3578][0-9]{9}";
String regex2 = "[\\w]+[@][\\w]{2,6}+([\\.][\\w]{2,6})+";
//先只考察账号的合法性,排查已存在的
if((str.matches(regex2)||str.matches(regex1)) && (!set.contains(str))) {
System.out.println("账号可用!");
zhangH = str;
miMa();
}else{
System.out.println("账号不可用或账号已存在!");
zhangHao(ptr);
}
}
public static void miMa() {
System.out.println("请输入注册密码(6-12位数字或字母):");
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String regex = "[\\da-zA-Z]{6,12}";
if(str.matches(regex)) {
System.out.println("请再次输入注册密码(确保与上次相同):");
String str1 = sc.next();
if(str.equals(str1)) {
miM = str;
System.out.println("恭喜你,注册成功!");
}else{
System.out.println("密码不匹配,请重新注册密码!");
miMa();
}
}else{
System.out.println("密码不可用!");
miMa();
}
}
}
|
|