Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import javax.swing.JOptionPane;
- public class UserLogin {
- public static void main(String[] args) {
- // arrays for usernames and passwords
- String[] usernames = { "x", "jimmy12", "john05", "lauren01", "katie90" };
- String[] passwords = { "x", "mets7654", "bass1276", "beauty0000", "password2176" };
- // handles user's choice
- String username, password;
- while (true) {
- char choice = JOptionPane.showInputDialog("(l)ogin to account\n" + "(q)uit program\n").charAt(0);
- if (choice == 'q') System.exit(0);
- username = JOptionPane.showInputDialog("Enter username ");
- password = JOptionPane.showInputDialog("Enter password ");
- int ui = Arrays.asList(usernames).indexOf(username);
- if (ui > -1 && ui == Arrays.asList(passwords).indexOf(password)) break;
- } // ends while loop
- JOptionPane.showMessageDialog(null, "You are logged in!");
- } // ends main
- } // ends class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement