Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import java.io.*;
  3. import java.util.*;
  4. public class user
  5. {
  6.     public static ArrayList<ArrayList<String>>  users;
  7.     public static void main(String[] args) throws IOException
  8.     {
  9.         boolean validInput = false;
  10.         int chances = 3;
  11.         String username = new String();
  12.         String password = new String();
  13.  
  14.         File inputFile = new File("users.txt");
  15.         users = new ArrayList<ArrayList<String>>();
  16.         users.add(new ArrayList<String>());
  17.         users.add(new ArrayList<String>());
  18.         users.add(new ArrayList<String>());
  19.        
  20.         String fileElements[];
  21.        
  22.         Scanner in = new Scanner(inputFile);
  23.        
  24.         while(in.hasNext())
  25.         {
  26.             fileElements = (in.nextLine()).split(",");
  27.             users.get(0).add(fileElements[0]);
  28.             users.get(1).add(fileElements[1]);
  29.             users.get(2).add((fileElements[2]));   
  30.         }
  31.        
  32.         in.close();
  33.    
  34.         while(!validInput && chances!=0)
  35.         {
  36.             username = JOptionPane.showInputDialog(null,"Enter your username");
  37.             password = JOptionPane.showInputDialog(null,"Enter your password");
  38.             for(int j = 0;j<users.get(0).size();j++)
  39.             {
  40.                 if(username.equals(users.get(0).get(j)) && password.equals(users.get(1).get(j)))
  41.                 {
  42.                     validInput = true;
  43.                     JOptionPane.showMessageDialog(null,"Login details are valid");
  44.                 }
  45.             }
  46.             if(!validInput)
  47.             {
  48.             chances--;
  49.             JOptionPane.showMessageDialog(null,"You have " + (chances) + " chances left");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement