Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Scanner;
- public class Login {
- private String input(String x) throws IOException{
- System.out.print(x);
- return new Scanner(System.in).nextLine();
- }
- public Login(String filename) throws IOException{
- for(int w = 0; w<3;w++){
- String username = input("username: ");
- String password = input("password: ");
- String both = "";
- try{
- Scanner t = new Scanner(new File(filename));
- while(t.hasNextLine()){
- both += t.nextLine()+" ";
- }
- t.close();
- }catch (ArrayIndexOutOfBoundsException e){
- }
- String Both[] = both.split(" ");
- int t = 0;
- for(int i = 0; i < Both.length; i += 2){
- if(Both[i].equals(username) && Both[i+1].equals(password) ){
- System.out.println("SUCCESSFUL, YOU ARE LOGGED IN!");
- System.exit(0);
- break;
- }
- if(!(Both[i].equals(username) || Both[i+1].equals(password))){
- t+=1;
- if(t == 2 && w != 2){
- System.out.println("USERNAME OR PASSWORD INCORRECT! TRY AGAIN");
- continue;
- }
- }
- }
- if(w == 2){
- System.out.println("YOU HAVE TRIED TOO MANY TIMES!");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement