Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileNotFoundException;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5.  
  6.  
  7. public class Login {
  8. private String input(String x) throws IOException{
  9. System.out.print(x);
  10. return new Scanner(System.in).nextLine();
  11. }
  12.  
  13. public Login(String filename) throws IOException{
  14. for(int w = 0; w<3;w++){
  15. String username = input("username: ");
  16. String password = input("password: ");
  17. String both = "";
  18. try{
  19. Scanner t = new Scanner(new File(filename));
  20. while(t.hasNextLine()){
  21. both += t.nextLine()+" ";
  22. }
  23. t.close();
  24. }catch (ArrayIndexOutOfBoundsException e){
  25.  
  26. }
  27. String Both[] = both.split(" ");
  28. int t = 0;
  29. for(int i = 0; i < Both.length; i += 2){
  30. if(Both[i].equals(username) && Both[i+1].equals(password) ){
  31. System.out.println("SUCCESSFUL, YOU ARE LOGGED IN!");
  32. System.exit(0);
  33. break;
  34. }
  35. if(!(Both[i].equals(username) || Both[i+1].equals(password))){
  36. t+=1;
  37. if(t == 2 && w != 2){
  38. System.out.println("USERNAME OR PASSWORD INCORRECT! TRY AGAIN");
  39. continue;
  40. }
  41. }
  42. }
  43. if(w == 2){
  44. System.out.println("YOU HAVE TRIED TOO MANY TIMES!");
  45. break;
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement