Please edit this class Authenticator. Remove breaks. Also create user array of size 100 rather than 3 different arrays. Also edit so it can be more OOP   import java.util.Scanner; public class AuthenticatorApp {     public static void main(String[] args) throws Exception {         Scanner input=new Scanner(System.in);         Authenticator obj=new Authenticator("user.data");         String Username,Password;         boolean done=false;         int count=0;         while(count<3)         {             System.out.print("Username? ");             Username=input.next();             System.out.print("Password? ");             Password=input.next();             obj.authenticate(Username,Password);             count++;         }         System.out.print("Too many failed attempts... please try again later");         input.close();     } } ------------------------------------------------------------------------------------------------------------ import java.io.File; import java.io.FileNotFoundException; import java.util.NoSuchElementException; import java.util.Scanner; class Authenticator {     int size;     String uname[];     String pwd[];     String hint[]; //constructor     Authenticator(String filename) throws FileNotFoundException     {         uname=new String[100];         pwd=new String[100];         hint=new String[100];         File file=new File(filename);         Scanner sc=new Scanner(file);         int pos = 0;         while(sc.hasNextLine())         {             String line=sc.nextLine();             String array[]=line.split("\\s");             uname[pos]=array[0];             pwd[pos]=array[1];             hint[pos]=array[2];             pos++;         }         size=pos;         sc.close();     }     void authenticate(String username, String password)     {         int flagU=1,count=1;         int i;         for( i=0;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please edit this class Authenticator. Remove breaks. Also create user array of size 100 rather than 3 different arrays. Also edit so it can be more OOP

 

import java.util.Scanner;

public class AuthenticatorApp {

    public static void main(String[] args) throws Exception {

        Scanner input=new Scanner(System.in);

        Authenticator obj=new Authenticator("user.data");

        String Username,Password;

        boolean done=false;

        int count=0;

        while(count<3)

        {

            System.out.print("Username? ");

            Username=input.next();

            System.out.print("Password? ");

            Password=input.next();

            obj.authenticate(Username,Password);

            count++;

        }

        System.out.print("Too many failed attempts... please try again later");

        input.close();

    }

}

------------------------------------------------------------------------------------------------------------
import java.io.File;

import java.io.FileNotFoundException;

import java.util.NoSuchElementException;

import java.util.Scanner;

class Authenticator

{

    int size;

    String uname[];

    String pwd[];

    String hint[];

//constructor

    Authenticator(String filename) throws FileNotFoundException

    {

        uname=new String[100];

        pwd=new String[100];

        hint=new String[100];

        File file=new File(filename);

        Scanner sc=new Scanner(file);

        int pos = 0;

        while(sc.hasNextLine())

        {

            String line=sc.nextLine();

            String array[]=line.split("\\s");

            uname[pos]=array[0];

            pwd[pos]=array[1];

            hint[pos]=array[2];

            pos++;

        }

        size=pos;

        sc.close();

    }

    void authenticate(String username, String password)

    {

        int flagU=1,count=1;

        int i;

        for( i=0;i<size;i++)

        {

            if(uname[i].equals(username))

            {

                flagU=0;

                break;

            }

        }

        if(flagU==1)

        {

            try {

                throw new Exception("UserName Not Exist");

            } catch (Exception e) {

                System.out.println(e.getMessage());

                return;

            }

        }

        boolean f= verifyPassword(password,i);

        if(f)

        {

            System.out.println("Welcome to the system");

            System.exit(0);

        }

        else

        {

            try {

                throw new Exception("*** Invalid password - hint: "+hint[i]);

            } catch (Exception e) {

                System.out.println(e.getMessage());

            }

        }

    }

    private boolean verifyPassword(String password,int index) {

        if(pwd[index].equals(password))

            return true;

        return false;

    }

}

 

here are some sample excutions of the program:

username? arnow
password? java
Welcome to the system

Sample Test Run #2

Given the same users.data file as above, execution of the program should look like:

username? weiss
password? dontremember
*** Invalid password - hint: woof-woof
username? weiss
password? puppy2
Welcome to the system

Sample Test Run #3

Given the same users.data file as above, execution of the program should look like:

username? sokol
password? CUNY
*** Invalid password - hint: college
username? sokol
password? SUNY
*** Invalid password - hint: college
username? sokol
password? BC
*** Invalid password - hint: college
Too many failed attempts... please try again later

Implement the following JAVA class name Authenticator:
State
An array of type User (use a capacity of 100 – I would recommend using a class constant the way I did in
the 06-Array class of Lecture 2).
An integer size
Behavior
A constructor accepting a file name, that opens a Scanner on the file and reads in User objects
A method named authenticate that accepts a username and password and attempts to authenticate them
against the User array (by doing a search).
Not finding the username in the array causes an exception to be thrown
finding the username, but not matching the password (via verifyPassword) causes an exception with a
different message to be thrown (this one with the password hint included).
See below for the exact exception messages expected
The return type of the method is void, i.e., the method returns nothing if the username and password are
matched; otherwise an exception is thrown, as described above. (This is a common pattem for
authentication methods – if everything is fine, the method simply returns, otherwise it throws an
exception.)
The name of your class should be Authenticator. Please remove the public attribute from the class header.
Your class is tested by a AuthenticatorApp class that reads in Users from a file using your read method,
loads them into an array and prompts the keyboard for a login sequence (username/password).
For example, if the file users.data contains:
weiss
puppy2 woof-woof
arnow java
cuppa
sokol brooklyn college
Transcribed Image Text:Implement the following JAVA class name Authenticator: State An array of type User (use a capacity of 100 – I would recommend using a class constant the way I did in the 06-Array class of Lecture 2). An integer size Behavior A constructor accepting a file name, that opens a Scanner on the file and reads in User objects A method named authenticate that accepts a username and password and attempts to authenticate them against the User array (by doing a search). Not finding the username in the array causes an exception to be thrown finding the username, but not matching the password (via verifyPassword) causes an exception with a different message to be thrown (this one with the password hint included). See below for the exact exception messages expected The return type of the method is void, i.e., the method returns nothing if the username and password are matched; otherwise an exception is thrown, as described above. (This is a common pattem for authentication methods – if everything is fine, the method simply returns, otherwise it throws an exception.) The name of your class should be Authenticator. Please remove the public attribute from the class header. Your class is tested by a AuthenticatorApp class that reads in Users from a file using your read method, loads them into an array and prompts the keyboard for a login sequence (username/password). For example, if the file users.data contains: weiss puppy2 woof-woof arnow java cuppa sokol brooklyn college
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education