Advertisement
adderk

Login Prototype

Oct 12th, 2016
643
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1. import java.util.*;
  2.  
  3.  
  4. public class LoginPrototype {
  5.     //Arraylist
  6.     private ArrayList<Credentials> allUsers = new ArrayList<Credentials>();
  7.  
  8.     //Main method to launch the app
  9.     public static void main(String[] args) {
  10.         LoginPrototype main = new LoginPrototype();
  11.         main.displayMainMenu();
  12.     }
  13.  
  14.     //Display method to view the app
  15.     private void displayMainMenu() {
  16.         int input;
  17.         do {
  18.             //Displaying the Main Menu
  19.             System.out.println("Menu Options");
  20.             System.out.println("[1] Login");
  21.             System.out.println("[2] Register");
  22.             System.out.println("[0] Quit");//5 Displaying Main Menu Options
  23.  
  24.             //allow Main Menu Input
  25.             Scanner sc = new Scanner(System.in);
  26.             input = sc.nextInt();
  27.  
  28.            //User Input turned to selection.
  29.             if (input > 2) {
  30.                 System.out.println("Only input [0]-[2]");
  31.             } else if (input == 1) {
  32.                 System.out.println("Login");
  33.                 handleLogin();
  34.             } else if (input == 2) {
  35.                 System.out.println("Register");
  36.                 register();
  37.             } else if (input == 0) {
  38.                 System.out.println("Thanks. Bye");
  39.                 break;
  40.             }
  41.         } while (input <= 2);
  42.     }
  43.  
  44.     private Credentials handleCredentialInput() {
  45.         Scanner sc = new Scanner(System.in);
  46.  
  47.         String username, password;
  48.  
  49.         System.out.println("Enter Username: ");
  50.         username = sc.next();
  51.         System.out.println("Enter Password: ");
  52.         password = sc.next();
  53.  
  54.         Credentials credentials = new Credentials(username, password);
  55.  
  56.         return credentials;
  57.     }
  58.  
  59.     //registering the usernames
  60.     private void register() {
  61.         handleCredentialInput();
  62.         if (allUsers.contains(handleCredentialInput())){
  63.             System.out.println("uName Exists");
  64.         }else{
  65.             allUsers.add(handleCredentialInput());
  66.             System.out.println("Successfully added");
  67.         }
  68.     }
  69.  
  70.     //Method collecting all the users in the arrayList
  71.     private void listUsers(){
  72.         for (Credentials c : allUsers){
  73.             System.out.println(c.getUsername());
  74.         }
  75.     }
  76.  
  77.     //Handling the Login of the Users
  78.     private void handleLogin() {
  79.         handleCredentialInput();
  80.         if(allUsers.contains(handleCredentialInput())) {
  81.             allUsers.get(allUsers.indexOf(handleCredentialInput()));
  82.             if (handleCredentialInput().getPassword().equals(allUsers.indexOf(handleCredentialInput())))
  83.             System.out.print("Logged In");
  84.         }else {
  85.             System.out.println("Wrong Username or Password");
  86.  
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement