Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Main program
- // Java auto includes the other UserData class
- import java.io.*;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- Vector<UserPass> Storage = new Vector<UserPass>();
- Scanner input = new Scanner(System.in);
- Character selChar;
- UserPass temp = new UserPass();
- do{
- temp = new UserPass();
- System.out.println("Enter Command:");
- System.out.println("L - Login");
- System.out.println("N - New User");
- System.out.println("S - Show All User Data");
- System.out.println("E - Exit");
- System.out.print("Selection:");
- String sel= input.nextLine();
- selChar= sel.charAt(0);
- switch(selChar)
- {
- case 'l': case 'L':
- {
- System.out.println("Enter Name:");
- temp.username = input.nextLine();
- System.out.println("Enter Password:");
- temp.password = input.nextLine();
- Boolean verified=false;
- for(Integer i=0; i<Storage.size(); i++)
- {
- if((temp.username == Storage.elementAt(i).username)
- && (temp.password==Storage.elementAt(i).password))
- { verified=true;
- }else
- {}
- }
- if(verified)
- System.out.println("Correct!");
- else
- System.out.println("Invalid username/password!");
- }break;
- case 'n': case 'N':
- {
- System.out.println("Enter Name:");
- temp.username = input.nextLine();
- System.out.println("Enter Password:");
- temp.password = input.nextLine();
- Storage.add(temp);
- }break;
- case 's': case 'S':
- System.out.println("**Printing User Data**");
- for(Integer i=0; i<Storage.size(); i++)
- {
- System.out.println(Storage.elementAt(i).username + "," + Storage.elementAt(i).password);
- }
- System.out.println("**End of Usernames/Passwords**");
- default: break;
- }
- } while(!(selChar=='E' || selChar=='e'));
- }
- }
- // Storage for username and passwords
- // This goes in a file called UserPass.java
- import java.io.*;
- public class UserPass
- {
- String username;
- String password;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement