JAVA CODE Authentication System For security-minded professionals, it is importa
ID: 3712999 • Letter: J
Question
JAVA CODE
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 acredentials 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:
? 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 credentials file
o Use the hashed passwords in the second column; the third column contains the actual passwords for testing and the fourth row contains 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 successful authentication
o The system information stored in the role file should be displayed. For example, if a zookeeper’s credentials is successfully authenticated, then the contents from the zookeeper file will be displayed. If an admin’s 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 You are 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.
credential file
Zookeeper
veterinarian
admin
Message Digest 5 (MD5) document
import java.security.MessageDigest;
public class MD5Digest {
public static void main(String[] args) throws Exception {
//Copy and paste this section of code
String original = "letmein"; //Replace "password" with the actual password inputted by the user
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));
}
//End copy/paste
System.out.println("original:" + original);
System.out.println("digested:" + sb.toString()); //sb.toString() is what you'll need to compare password strings
}
}
Pseudocode: Break down the problem statement into programming terms through creation of pseudocode. The pseudocode should demonstrate your breakdown of the program from the problem statement into programming terms. Explain whether the pseudocode differs from the submitted program and document any differences and the reason forchanges.
Explanation / Answer
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class Credentials {
public static void Credentials(String original) throws Exception {
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));
}
return;
}
}
public class Authentication {
public static void main(String[] args) throws Exception {
Map<String, String> credentials = new HashMap<>();
credentials.put("griffin.keyes", "108de81c31bf9c622f76876b74e9285f");
credentials.put("rosario.dawson", "3e34baa4ee2ff767af8c120a496742b5");
credentials.put("bernie.gorilla", "a584efafa8f9ea7fe5cf18442f32b07b");
credentials.put("donald.monkey", "17b1b7d8a706696ed220bc414f729ad3");
credentials.put("jerome.grizzlybear", "3adea92111e6307f8f2aae4721e77900");
credentials.put("bruce.grizzlybear", "0d107d09f5bbe40cade3de5c71e9e9b7");
boolean success = false;
BufferedReader scnr = new BufferedReader(new InputStreamReader(System.in));
String userName = null;
for (int i = 0; i < 3; ++i){
System.out.println("Enter username:");
userName = scnr.readLine();
System.out.println("Enter password:");
String password1 = scnr.readLine();
}
String hash = credentials.get(userName);
String password1;
String zookeeper = "griffin.keyes";
String zookeeper1 = "donald.monkey";
String veterinarian = "bernie.gorilla";
String veterinarian1 = "jerome.grizzlybear";
String Admin = "rosario.dawson";
String Admin1 = "bruce.grizzlybear";
String password;
if (userName.equals(zookeeper)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, Zookeeper! " +
" " + "As zookeeper, you have access to all of the"
+ " animals'" + " information and their" + " daily"
+ " monitoring logs. This " + "allows you to track their "
+ "feeding habits, habitat conditions, and general welfare.");
System.out.println();
}
if (userName.equals(zookeeper1)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, Zookeeper! " +
" " + "As zookeeper, you have access to all of the"
+ " animals'" + " information and their" + " daily"
+ " monitoring logs. This " + "allows you to track their "
+ "feeding habits, habitat conditions, and general welfare.");
System.out.println();
}
if (userName.equals(veterinarian)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, Veterinarian! " + " " + "As "
+ "veterinarian, you have access to all of the animals'"
+ " health records. This allows you to view each animal's "
+ "medical history and current treatments/illnesses "
+ "(if any), and to maintain a vaccination log.");
System.out.println();
}
if (userName.equals(veterinarian1)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, Veterinarian! " + " " + "As "
+ "veterinarian, you have access to all of the animals'"
+ " health records. This allows you to view each animal's "
+ "medical history and current treatments/illnesses "
+ "(if any), and to maintain a vaccination log.");
System.out.println();
}
if (userName.equals(Admin)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, System Admin! " + " " + "As"
+ " administrator, you have access to the zoo's main "
+ "computer system. This allows you to monitor users in "
+ "the system and their roles.");
System.out.println();
}
if (userName.equals(Admin1)) {
System.out.println("Please enter password");
System.out.println();
System.out.println("Hello, System Admin! " + " " + "As"
+ " administrator, you have access to the zoo's main "
+ "computer system. This allows you to monitor users in "
+ "the system and their roles.");
System.out.println();
}
else {
System.out.println("Please enter correct login information!");
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.