Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class LoginPrototype {
- //Arraylist
- private ArrayList<Credentials> allUsers = new ArrayList<Credentials>();
- //Main method to launch the app
- public static void main(String[] args) {
- LoginPrototype main = new LoginPrototype();
- main.displayMainMenu();
- }
- //Display method to view the app
- private void displayMainMenu() {
- int input;
- do {
- //Displaying the Main Menu
- System.out.println("Menu Options");
- System.out.println("[1] Login");
- System.out.println("[2] Register");
- System.out.println("[0] Quit");//5 Displaying Main Menu Options
- //allow Main Menu Input
- Scanner sc = new Scanner(System.in);
- input = sc.nextInt();
- //User Input turned to selection.
- if (input > 2) {
- System.out.println("Only input [0]-[2]");
- } else if (input == 1) {
- System.out.println("Login");
- handleLogin();
- } else if (input == 2) {
- System.out.println("Register");
- register();
- } else if (input == 0) {
- System.out.println("Thanks. Bye");
- break;
- }
- } while (input <= 2);
- }
- private Credentials handleCredentialInput() {
- Scanner sc = new Scanner(System.in);
- String username, password;
- System.out.println("Enter Username: ");
- username = sc.next();
- System.out.println("Enter Password: ");
- password = sc.next();
- Credentials credentials = new Credentials(username, password);
- return credentials;
- }
- //registering the usernames
- private void register() {
- handleCredentialInput();
- if (allUsers.contains(handleCredentialInput())){
- System.out.println("uName Exists");
- }else{
- allUsers.add(handleCredentialInput());
- System.out.println("Successfully added");
- }
- }
- //Method collecting all the users in the arrayList
- private void listUsers(){
- for (Credentials c : allUsers){
- System.out.println(c.getUsername());
- }
- }
- //Handling the Login of the Users
- private void handleLogin() {
- handleCredentialInput();
- if(allUsers.contains(handleCredentialInput())) {
- allUsers.get(allUsers.indexOf(handleCredentialInput()));
- if (handleCredentialInput().getPassword().equals(allUsers.indexOf(handleCredentialInput())))
- System.out.print("Logged In");
- }else {
- System.out.println("Wrong Username or Password");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement