注册账号界面
登录账号界面
重置密码界面
IUserDao.java
public interface IUserDao {
abstract public void AddUser();
abstract public void FindUser();
abstract public void ResetPassword();
}
JavaBean.java
public class JavaBean {
public static String User;
public static String Password;
public static String ConfirmPassword;
public static String Birthday;
public JavaBean(String user, String password, String confirmPassword, String birthday) {
User = user;
Password = password;
ConfirmPassword = confirmPassword;
Birthday = birthday;
}
public String getUser() {
return User;
}
public void setUser(String user) {
User = user;
}
public String getPassword() {
return Password;
}
public void setPassword(String password) {
Password = password;
}
public String getConfirmPassword() {
return ConfirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
ConfirmPassword = confirmPassword;
}
public String getBirthday() {
return Birthday;
}
public void setBirthday(String birthday) {
Birthday = birthday;
}
}
UserDaoImpl.java
import java.util.Scanner;
public class UserDaoImpl implements IUserDao {
public String UserName1;
public String UserPassword1;
public int count1 = 0;
public int count2 = 0;
public int count3 = 0;
public int count4 = 0;
public int count5 = 0;
public void AddUser() { //添加用户(注册功能)
System.out.println("^^^^^^^^^^^^^^^^注册界面^^^^^^^^^^^^^^^^");
System.out.println("您还未注册,请先进行注册");
Scanner scanner1 = new Scanner(System.in);
System.out.print("请输入您的用户名称:");
JavaBean.User = scanner1.nextLine();
System.out.print("请输入您的用户生日:");
JavaBean.Birthday = scanner1.nextLine();
while (count1 <= 3) {
System.out.print("请输入用户密码:");
JavaBean.Password = scanner1.nextLine();
System.out.print("请确认用户密码:");
JavaBean.ConfirmPassword = scanner1.nextLine();
if (JavaBean.ConfirmPassword.equals(JavaBean.Password)) {
System.out.println("\n密码设置成功,请重新登录!");
System.out.println("正在跳转中,请稍后!");
FindUser();
} else {
System.out.println("密码前后设置不一致,请重新设置!");
count1 = count1 + 1;
}
}
}
public void FindUser() { //查找用户(登录功能)
while (count2 <= 3) {
System.out.println("****************登录界面*****************");
System.out.print("用户登录名:");
Scanner scanner2 = new Scanner(System.in);
String UserName2 = scanner2.nextLine();
if (UserName2.equals(JavaBean.User)) {
System.out.println("✔");
System.out.print("用户密码:");
String UserPassword2 = scanner2.nextLine();
if (JavaBean.Password.equals(UserPassword2)) {
System.out.println("✔");
System.out.println("登陆成功!");
System.out.println("++++++++++++++++用户信息++++++++++++++++");
System.out.println(" 用户名:"+JavaBean.User);
System.out.println(" 生 日:"+JavaBean.Birthday);
System.out.println("+++++++++++++++++++++++++++++++++++++++");
count2=4;
count1=4;
} else {
System.out.println("密码错误!请重新输入");
count2 = count2 + 1;
count3 = count3 + 1;
}
if(count3==4){
System.out.println("输入次数过多,请稍后再试");
}
} else {
System.out.print("查无此用户!请重新输入,注册账号请输入1,重新登录按任意键>>>");
Scanner Again=new Scanner(System.in);
String AgainNumber=Again.nextLine();
if(AgainNumber.equals("1")){
AddUser();
}else {
FindUser();
}
}
System.out.println("\n");
}
}
public void ResetPassword(){ //用户(重置密码)
while (count4 <= 3) {
System.out.println("================密码重置================");
System.out.print("用户登录名:");
Scanner scanner3 = new Scanner(System.in);
String UserName3 = scanner3.nextLine();
if (UserName3.equals(JavaBean.User)) {
System.out.print("请输入旧的密码:");
String UserPassword3 = scanner3.nextLine();
if (UserPassword3.equals(JavaBean.Password)) {
System.out.print("验证通过,请输入新的密码:");
String UserPassword4 = scanner3.nextLine();
System.out.print("请确认用户新的密码:");
String UserPassword4Confirm = scanner3.nextLine();
if (UserPassword4Confirm.equals(UserPassword4)) {
JavaBean.Password=UserPassword4Confirm;
System.out.println("已更换为新的密码!请重新登录!");
count2 =0;
count3 =0;
count4 =4;
while (count2 <= 3) {
System.out.println("****************登录界面*****************");
System.out.print("用户登录名:");
Scanner scanner2 = new Scanner(System.in);
String UserName2 = scanner2.nextLine();
if (UserName2.equals(JavaBean.User)) {
System.out.println("✔");
System.out.print("用户密码:");
String UserPassword2 = scanner2.nextLine();
if (JavaBean.Password.equals(UserPassword2)) {
System.out.println("✔");
System.out.println("登陆成功!");
System.out.println("++++++++++++++++用户信息++++++++++++++++");
System.out.println(" 用户名:"+JavaBean.User);
System.out.println(" 生 日:"+JavaBean.Birthday);
System.out.println("+++++++++++++++++++++++++++++++++++++++");
count2=4;
count1=4;
count5=1;
} else {
System.out.println("密码错误!请重新输入");
count2 = count2 + 1;
count3 = count3 + 1;
}
if(count3==4){
System.out.println("输入次数过多,请稍后再试");
}
} else {
System.out.print("查无此用户!请重新输入,注册账号请输入1,重新登录按任意键>>>");
Scanner Again=new Scanner(System.in);
String AgainNumber=Again.nextLine();
if(AgainNumber.equals("1")){
AddUser();
}else {
FindUser();
}
}
System.out.println("\n");
}
}else {
System.out.println("密码前后设置不一致,请重新设置!");
count4 = count4 + 1;
}
if(count4==4 && count5==0){
System.out.println("输入次数过多,请稍后再试");
}
}else{
System.out.println("旧密码验证不通过!请重新输入!");
}
}else {
System.out.print("查无此用户!请重新输入,注册账号请输入1,重新登录按任意键>>>");
Scanner Again=new Scanner(System.in);
String AgainNumber=Again.nextLine();
if(AgainNumber.equals("1")){
AddUser();
ResetPassword();
}else {
count2=0;
count3=0;
FindUser();
}
}
}
}
}
TestUser.java
import java.util.Scanner;
public class TestUser{
public static void main(String[] args){
System.out.println("---------------------------------------");
System.out.println("1.注册账号 2.登录账号 3.重置密码");
System.out.println("---------------------------------------");
System.out.print("请选择要执行的操作(直接输入数字)>>>");
UserDaoImpl userDaoImpl1=new UserDaoImpl();
Scanner input=new Scanner(System.in);
int number=input.nextInt();
switch (number){
case 1:
userDaoImpl1.AddUser();
break;
case 2:
userDaoImpl1.FindUser();
break;
case 3:
userDaoImpl1.ResetPassword();
}
}
}
目录