im having trouble with this assignment, creating methods is confusing me i dont get what im supposed to put in the parentheses following them.. and i also cant figure out much else anyway. if someone could give me some step by step on how to complete this - i dont just want someone to do it for me i'd like to know how its done so i can actually learn this >.<
below is instructions for my assignment.
~~~~
Authentication
You were hired to be part of team developing an application that requires users to login and be authenticated with a password. Your specific job is to write the authentication part of the system. This requires the beginning of the application that prompts the user for a login and password, verifies if it correctly matches the pair stored in a file, and reports back if it was successful or not.
Since your part of the application is only the beginning of a much larger program, you will be required to write the authentication code in a seperate class. This seperate class is to be called Authenticate.
The Authenticate class will need 1 instance variable only:
* a 2-D array with a maximum of 10 logins possible (reference a constant that YOU define for the number 10).
The Authenticate class will need 3 methods created:
* Authenticate - constructor method that takes a String as a parameter which is the name of the file to be read in that contains the login/password pairs.
This method should instantiate the 2-D array of login/password pairs and call the loadPasswordFile method by sending the name of the file.
* loadPasswordFile - method that takes a String as a parameter which is the name of the file to be read in. When you open the file in this method, you'll need to catch errors that Java may throw - put the code within a try...catch block.
Example:
try
{
// put code here that may throw an error
} catch ( Exception e )
{
// do whatever to handle the error
}
For more info, see Exceptions in Java textbook.
Each line in the file is a login/password pair, separated with a semi-colon. You have lots of options on how to parse them.
Store the pair in the 2-D array (instance variable).
This method should be private since outside classes should not be able to access it.
Example password file:
CookieMonster;qwerty
liz;jkl
* verify - takes two String parameters - the login name and passwords.
Returns an integer ID number of whether or not login matches the password or there's an error.
Method walks through the 2-D array of login/password pairs and searches for a match to the login name parameter. If they match, check and verify that the password matches. Return an appropriate error identifier if the login doesn't exist or the password doesn't match.
Note: There may not be 10 name/passwords in the file, but your code should still work - HINT: check for null.
Example output
Run without any command-line arguments:
Usage: CVS passwordFileName
Run with command-line argument pswds which is the file containing login/password pairs
You are entering a secure site.
What is your login name: liz
What is your password: jkl
Good to go! Welcome back liz
You are entering a secure site.
What is your login name: CookieMonster
What is your password: qwerty
Good to go! Welcome back CookieMonster
You are entering a secure site.
What is your login name: liz
What is your password: aaaaaaaaah
Password doesn't match. Good bye.
You are entering a secure site.
What is your login name: java
What is your password: jkl
Login does not exist. Good bye.
The CVS class with main method
In the main program class you will have the main method that is executed when the program runs (you cannot run the Authenticate class). You will also need to create a support method in this class that handles the prompting of the user for their login and password.
The skeleton of the CVS class is provided. DO NOT CHANGE IT IN ANY WAY! You are only to add to the promptUser method.
import java.awt.*;
import java.util.*;
import java.io.*;
/* Program a control version software program */
public class CVS
{
static Authenticate auth; // class variable
public static void main( String args[])
{
if( args.length != 1 ) // didn't run program right
{
System.out.println( "Usage: CVS passwordFileName" );
return;
}
auth = new Authenticate( args[0] );
promptUser( );
}
/** Method to prompt the user for login and password,
read in the values, then call the verify method
in Authenticate to verify login and password matches
or verify returns an error identifier and will print
either success or error message.
PRE-conditions: none
POST-conditions: prints success or error message
*/
private static void promptUser( )
{
// add your code here, reference the auth class variable
}
}
~~~~