Advertisement
Guest User

Untitled

a guest
Jun 21st, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. // Main program
  2. // Java auto includes the other UserData class
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Vector<UserPass> Storage = new Vector<UserPass>();
  9.         Scanner input = new Scanner(System.in);
  10.         Character selChar;
  11.         UserPass temp = new UserPass();
  12.         do{
  13.             temp = new UserPass();
  14.             System.out.println("Enter Command:");
  15.             System.out.println("L - Login");
  16.             System.out.println("N - New User");
  17.             System.out.println("S - Show All User Data");
  18.             System.out.println("E - Exit");
  19.             System.out.print("Selection:");
  20.             String sel= input.nextLine();
  21.             selChar= sel.charAt(0);
  22.             switch(selChar)
  23.             {
  24.                 case 'l': case 'L':
  25.                 {
  26.                     System.out.println("Enter Name:");
  27.                     temp.username = input.nextLine();
  28.                     System.out.println("Enter Password:");
  29.                     temp.password = input.nextLine();
  30.                     Boolean verified=false;
  31.                     for(Integer i=0; i<Storage.size(); i++)
  32.                     {
  33.                         if((temp.username == Storage.elementAt(i).username)
  34.                             && (temp.password==Storage.elementAt(i).password))
  35.                         {       verified=true;
  36.                         }else
  37.                         {}
  38.                     }
  39.                     if(verified)
  40.                         System.out.println("Correct!");
  41.                     else
  42.                         System.out.println("Invalid username/password!");
  43.                 }break;
  44.                 case 'n': case 'N':
  45.                 {
  46.                     System.out.println("Enter Name:");
  47.                     temp.username = input.nextLine();
  48.                     System.out.println("Enter Password:");
  49.                     temp.password = input.nextLine();
  50.                     Storage.add(temp);
  51.                     }break;
  52.                 case 's': case 'S':
  53.                     System.out.println("**Printing User Data**");
  54.                     for(Integer i=0; i<Storage.size(); i++)
  55.                     {
  56.                         System.out.println(Storage.elementAt(i).username + "," + Storage.elementAt(i).password);
  57.                     }
  58.                     System.out.println("**End of Usernames/Passwords**");                  
  59.                 default: break;
  60.             }
  61.             } while(!(selChar=='E' || selChar=='e'));
  62.         }
  63.    }
  64.  
  65.  
  66. // Storage for username and passwords
  67. // This goes in a file called UserPass.java
  68. import java.io.*;
  69.  
  70. public class UserPass
  71. {
  72.         String username;
  73.         String password;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement