Question
Prompt: Option 1: Authentication System For security-minded professionals, it is important that only the appropriate people gain access to data in a computer system. This
Prompt:
Option 1: Authentication System
For security-minded professionals, it is important that only the appropriate people gain access to data in a computer system. This is called authentication. Once users gain entry, it is also important that they only see data related to their role in a computer system. This is called authorization. For the zoo, you will develop an authentication system that manages both authentication and authorization. You have been given a credentials file that contains credential information for authorized users. You have also been given three files, one for each role: zookeeper, veterinarian, and admin. Each role file describes the data the particular role should be authorized to access. Create an authentication system that does all of the following:
? ? ?
?
? ?
? ?
You are
Asks the user for a username Asks the user for a password Converts the password using a message digest five (MD5) hash
o It is not required that you write the MD5 from scratch. Use the code located in this document and follow the comments in it to perform this operation.
Checks the credentials against the valid credentials provided in the credentialsfile
o Usethehashedpasswordsinthesecondcolumn;thethirdcolumncontainstheactualpasswordsfortestingandthefourthrowcontains the role of each user.
Limits failed attempts to three before notifying the user and exiting the program Gives authenticated users access to the correct role file after successfulauthentication
o The system information stored in the role file should be displayed. For example, if a zookeepers credentials is successfully authenticated, then the contents from the zookeeper file will be displayed. If an admins credentials is successfully authenticated, then the contents from the admin file will be displayed.
Allows a user to log out Stays on the credential screen until either a successful attempt has been made, three unsuccessful attempts have been made, or a user chooses to exit
allowed to add extra roles if you would like to see another type of user added to the system, but you may not remove any of the existing roles.
I need some help with figuring how to get this code to work. I have done most of it and it works for most of the function, but the text won't come up after the correct log in info is entered.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
My Code:
import java.io.File; import java.security.MessageDigest; import java.util.Scanner;
public class Authentication {
public static void main(String[] args) throws Exception {
//Create a scanner object to read input from the console Scanner readInput = new Scanner(System.in);
//Declare a variable to keep track the number of attempts int attempts = 0;
/*Repeat until a successful attempt has been made or
three unsuccessful attempts have been made or
a user chooses to exit*/ while (true) {
//Ask the user for a username System.out.print("Enter user name: ");
String uName = readInput.nextLine();
//Ask the user for a password System.out.print("Enter password: ");
String original = readInput.nextLine();
//Convert the password using a message digest five (MD5) hash MessageDigest md = MessageDigest.getInstance("MD5");
md.update(original.getBytes());
byte[] digest = md.digest();
StringBuffer sb = new StringBuffer();
for (byte b : digest) {
sb.append(String.format("%02x", b & 0xff));
}
//Declare a boolean variable to keep track whether //a login is successful or not boolean authenticationSuccess = false;
//Open credentials file Scanner readCred; readCred = new Scanner(new File("/Users/kleberdesouza/Desktop/IT-145 Kleber DeSouza/Authentication/build/classes/authentication/credentials.txt"));
//Search for the user credentials in the credentials file while (readCred.hasNextLine()) {
String record = readCred.nextLine();//Read a record
String columns[] = record.split("\t");//Split the record into individual fields
/*Check the credentials against the valid credentials provided in the credentials file*/ //Check user name. if (columns[0].trim().equals(uName)) {
/*If user name is matched, check whether the Converted password using a message digest five password with hashed password in the second column*/ if (columns[1].trim().equals(sb.toString()))//Check password {
//If the passwords are same, set the boolean value //uthenticationSuccess to true authenticationSuccess = true;//Login success
//Open the role file Scanner readRole; readRole = new Scanner(new File(columns[3].trim() + ".txt"));
//Display the information stored in the role file while (readRole.hasNextLine()) {
System.out.println(readRole.nextLine());
}
break;
}
}
}
//If login successful, ask the user whether the user wants to log out or not if (authenticationSuccess) {
System.out.println("Do you want to log out(y): ");
String choice = readInput.nextLine();
//If user wants to log out, exit the system. if (choice.toLowerCase().charAt(0) == 'y') {
System.out.println("Successfully loged out.");
break;
} //If user wants to continue, set the boolean value //uthenticationSuccess to true for new login else {
authenticationSuccess = false;
}
} //If login is not successful, update the number of attempts else {
attempts++;
//If maximum attempts reached, notify the user and exit the program if (attempts == 3) {
System.out.println("Maximum attempts reached! Exiting...");
break;
} //otherwise, prompt to enter credentials again else {
System.out.println("Please enter correct credentials!");
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////?
The output:
Authentication - NetBeans IDE 8.2Step 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