bickey

Yahoo : UserLogin

Feb 9th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class UserLogin {
  4.     public static void main(String[] args) {
  5.         String[] usernames = { "x", "jimmy12", "john05" , "lauren01", "katie90"};
  6.         String[] passwords = { "x", "mets7654", "bass1276", "beauty0000", "password2176"};
  7.  
  8.         boolean done = false;
  9.         do {
  10.             String input = JOptionPane.showInputDialog("(l)ogin to account\n(q)uit program");
  11.             if (input.equalsIgnoreCase("q")) {
  12.                 done = true;
  13.             } else {
  14.                 String username = JOptionPane.showInputDialog("Enter username");
  15.                 String password = JOptionPane.showInputDialog("Enter password");
  16.                 String message = "Invalid try again";
  17.  
  18.                 for(int i = 0; i < usernames.length; i++) {
  19.                     if (usernames[i].equalsIgnoreCase(username)) {
  20.                         if (passwords[i].equals(password)) {
  21.                             message = "you are logged in";
  22.                             done = true;
  23.                             break;
  24.                         }
  25.                     }
  26.                 }
  27.  
  28.                 JOptionPane.showMessageDialog(null, message);
  29.             }    
  30.         } while (!done);
  31.     }
  32. }
Add Comment
Please, Sign In to add comment