Advertisement
Guest User

Untitled

a guest
Feb 15th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 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 = "";
  12.         String password = "";
  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.        
  33.         in.close();
  34.            
  35.         while(!validInput && chances != 0)
  36.         {  
  37.             for(int i = 0;i<users.get(0).size() && !validInput; i++)
  38.             {
  39.                 username = JOptionPane.showInputDialog(null,"Enter your username");
  40.                 password = JOptionPane.showInputDialog(null,"Enter your password");
  41.                 if(username == users.get(0).get(i) && password == users.get(1).get(i))
  42.                 {
  43.                     validInput = true;
  44.                     JOptionPane.showMessageDialog(null,"Input is correct");
  45.                 }
  46.                 else
  47.                 {
  48.                     chances--;
  49.                     JOptionPane.showMessageDialog(null,"You have " + (chances) + " chances left");
  50.                 }
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement