Hello! I am trying to create a simple register/log in menu which allows users to enter the system using that username and password. I have already created the 'Register' section but I have difficulty linking it with the Username and Password in the 'Log in' section. Do I have to create a database which stores Usernames and Passwords in order to do so? Thanks in advance.
import java.util.*;
public class Menu {
public static void main (String[] args){
Random generator = new Random();
Scanner sc = new Scanner(System.in);
char[] Email, Username, Password, pass1, user1;
String Name, Surname, Ans;
int age, sqchoice, choice;
System.out.println("Welcome!");
System.out.println("\n[1] Register");
System.out.println("[2] Log in");
System.out.println("[3] Forgot Password/Username");
System.out.println("[4] Quit");
System.out.print("\nEnter your choice: ");
choice = sc.nextInt();
switch(choice){
case 1:
System.out.println("\nKindly enter information below:");
System.out.print("\nName: ");
Name = sc.next();
System.out.print("Surname: ");
Surname = sc.next();
System.out.print("Age: ");
age = sc.nextInt();
System.out.print("Email Address: ");
String input = sc.next();
Email = input.toCharArray();
System.out.print("Username: ");
String input1 = sc.next();
Username = input1.toCharArray();
System.out.print("Password: ");
String input2 = sc.next();
Password = input2.toCharArray();
System.out.println("\nSecurity Questions: ");
System.out.println("[1] What was your childhood nickname?");
System.out.println("[2] What is the name of your favorite childhood friend?");
System.out.println("[3] What is your maternal grandmother's maiden name?");
System.out.println("[4] What is your oldest cousin's first and last name?");
System.out.print("\nEnter your choice: ");
sqchoice = sc.nextInt();
System.out.print("\nAnswer: ");
Ans = sc.next();
int number = generator.nextInt(1000000) + 1;
System.out.println("\nYour Unique Number: "+number);
case 2:
System.out.print("\nUsername: ");
String input3 = sc.next();
user1 = input3.toCharArray();
System.out.print("Password: ");
String input4 = sc.next();
pass1 = input4.toCharArray();
if ((Username=user1) && (Password=pass1)){
System.out.print("WIN");
}else{
System.out.print("FAIL");
}
break;
}
}
}