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 = new String();
- String password = new String();
- 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)
- {
- username = JOptionPane.showInputDialog(null,"Enter your username");
- password = JOptionPane.showInputDialog(null,"Enter your password");
- for(int j = 0;j<users.get(0).size();j++)
- {
- if(username.equals(users.get(0).get(j)) && password.equals(users.get(1).get(j)))
- {
- validInput = true;
- JOptionPane.showMessageDialog(null,"Login details are valid");
- }
- }
- if(!validInput)
- {
- chances--;
- JOptionPane.showMessageDialog(null,"You have " + (chances) + " chances left");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement