Question
Implement the following class name Authenticator: State An array of type User (use a capacity of 100 I would recommend using a class constant the
Implement the following 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 pattern 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
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
Assuming the existence of the Authenticator class of Lab 4.4, code an AuthenticatorApp application that reproduces the behavior of the sample runs of Lab 4.4, i.e., your app should instantiate an Authenticator object passing it the filename users.data, and then proceed to prompt the user at the keyboard for a user name and password; handling any exceptions in the manner described in Lab 4.4.
The name of your class should be AuthenticatorApp.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started