Advertisement
Guest User

login

a guest
Feb 9th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.util.Arrays;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class UserLogin {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         // arrays for usernames and passwords
  10.  
  11.         String[] usernames = { "x", "jimmy12", "john05", "lauren01", "katie90" };
  12.         String[] passwords = { "x", "mets7654", "bass1276", "beauty0000", "password2176" };
  13.  
  14.         // handles user's choice
  15.         String username, password;
  16.        
  17.         while (true) {
  18.  
  19.             char choice = JOptionPane.showInputDialog("(l)ogin to account\n" + "(q)uit program\n").charAt(0);
  20.             if (choice == 'q') System.exit(0);
  21.  
  22.             username = JOptionPane.showInputDialog("Enter username ");
  23.             password = JOptionPane.showInputDialog("Enter password ");
  24.  
  25.             int ui = Arrays.asList(usernames).indexOf(username);
  26.             if (ui > -1 && ui == Arrays.asList(passwords).indexOf(password)) break;
  27.            
  28.         } // ends while loop
  29.        
  30.         JOptionPane.showMessageDialog(null, "You are logged in!");
  31.  
  32.     } // ends main
  33.  
  34. } // ends class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement