Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.io.*;
- import java.util.*;
- public class user
- {
- public static ArrayList<ArrayList<String>> users;
- public static void main(String[] args) throws IOException
- {
- boolean validInput = false;
- int chances = 3;
- String username = "";
- String password = "";
- File inputFile = new File("users.txt");
- users = new ArrayList<ArrayList<String>>();
- users.add(new ArrayList<String>());
- users.add(new ArrayList<String>());
- users.add(new ArrayList<String>());
- String fileElements[];
- Scanner in = new Scanner(inputFile);
- while(in.hasNext())
- {
- fileElements = (in.nextLine()).split(",");
- users.get(0).add(fileElements[0]);
- users.get(1).add(fileElements[1]);
- users.get(2).add((fileElements[2]));
- }
- in.close();
- while(!validInput && chances != 0)
- {
- for(int i = 0;i<users.get(0).size() && !validInput; i++)
- {
- username = JOptionPane.showInputDialog(null,"Enter your username");
- password = JOptionPane.showInputDialog(null,"Enter your password");
- if(username == users.get(0).get(i) && password == users.get(1).get(i))
- {
- validInput = true;
- JOptionPane.showMessageDialog(null,"Input is correct");
- }
- else
- {
- chances--;
- JOptionPane.showMessageDialog(null,"You have " + (chances) + " chances left");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement