Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Netbeans code These instructions are very crucial to follow. The credential

ID: 3576859 • Letter: J

Question

Java Netbeans code

These instructions are very crucial to follow. The credential file must be read, the password must be converted to (MD5) hash, each user is part of a group and need to have the group welcome screen on a successful login.

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:
* 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.

credentials file: This file must be used to validate user logins.

Each user is part of a group. when they login the welcome screen for each group must have the following welcome screen

Zookeeper file:

Admin file:

MD5 file:

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
   }

}

Explanation / Answer

credentials.txt

griffin.keyes, 108de81c31bf9c622f76876b74e9285f, "alphabet soup",zookeeper
rosario.dawson,3e34baa4ee2ff767af8c120a496742b5,   "animal doctor"   ,admin
bernie.gorilla,   a584efafa8f9ea7fe5cf18442f32b07b,   "secret password",   veterinarian
donald.monkey,   17b1b7d8a706696ed220bc414f729ad3,   "M0nk3y business",   zookeeper
jerome.grizzlybear,   3adea92111e6307f8f2aae4721e77900,   "grizzly1234",   veterinarian
bruce.grizzlybear,   0d107d09f5bbe40cade3de5c71e9e9b7,   "letmein",   admin

admin.txt

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.

Vet.txt

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.

Authentication.java

import java.io.BufferedReader;
import java.io.FileReader;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Scanner;

public class Authentication {

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

       printFile(checkPassword(checkUserName(userInfo())));
      
       }catch(Exception e){
           System.out.println(e.getMessage());
       }

   }

   public static ArrayList<UserInfo> userInfo() throws Exception {
       String[] userInfo;

       ArrayList<UserInfo> users = new ArrayList<UserInfo>();

       String lineToBeRead = null;
       FileReader reader = null;
       BufferedReader bufferedReader = null;

       reader = new FileReader("credentials.txt");

       bufferedReader = new BufferedReader(reader);

       while ((lineToBeRead = bufferedReader.readLine()) != null) {
           userInfo = lineToBeRead.split(",");
           String userName = userInfo[0].trim();
           String hashP = userInfo[1].trim();
           String pw = userInfo[2].trim();
           String position = userInfo[3].trim();

           UserInfo user = new UserInfo(userName, hashP, pw, position);
           users.add(user);
       }
       return users;
   }

   public static UserInfo checkUserName(ArrayList<UserInfo> users) throws Exception {
       Scanner sc = new Scanner(System.in);

       System.out.print("Enter username: ");
       String input = sc.next();

       int length = users.size();
       int tries = 0;
       do {
           for (int i = 0; i < length; i++) {
               String username = users.get(i).getUserName();
               if (username.equals(input)) {

                   return users.get(i);
               }

           }
           System.out.print("Invalid Username, Please try again: ");
           tries++;
           if (tries == 3) {
               throw new Exception("Too many failed attempts...now exiting");
           }
           input = sc.next();
       } while (true);
   }

   public static UserInfo checkPassword(UserInfo user) throws Exception {
       Scanner sc = new Scanner(System.in);
       int tries = 0;
       System.out.print("Enter password: ");
       String input = sc.nextLine();
       String pass = user.getHash();
       do {
           String original = input;

           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));
           }

           String userHash = sb.toString();
           if (userHash.equals(pass)) {
               return user;
           }
           System.out.print("Invalid password, please try again: ");
           tries++;
           if (tries == 3) {
               throw new Exception("Too many failed attempts...now exiting");
           }

           input = sc.next();
       } while (true);

   }

   public static void printFile(UserInfo user) throws Exception {
       Scanner input = new Scanner(System.in);
       String choice = "y";
      
do{
       String position = user.getPosition();
       String zooPath = "Vet.txt";
       String adminPath = "admin.txt";
       String vetPath = "admin.txt";

       String lineToBeRead = null;
       FileReader reader = null;
       BufferedReader bufferedReader = null;
       // File vetFile = new File(vetPath);
       // File zookeeperFile = new File(zooPath);
       // File adminFile = new File(adminPath);

       if (position.equals("zookeeper")) {
           reader = new FileReader(zooPath);
       } else if (position.equals("admin")) {
           reader = new FileReader(adminPath);

       } else if (position.equals("veterinarian")) {
           reader = new FileReader(vetPath);

       }
       bufferedReader = new BufferedReader(reader);

       System.out.println(bufferedReader.readLine());

       while ((lineToBeRead = bufferedReader.readLine()) != null) {
           System.out.println(bufferedReader.readLine());

       }
       System.out.print("Do you want to log out? y/n: ");
       choice = input.nextLine();
}while(!choice.equalsIgnoreCase("y"));

       // reader = new FileReader("C:\Users\emmanuel\workspace\Final
       // Project SNHU\credentials.txt");
       //
       // bufferedReader = new BufferedReader(reader);

       // while ((lineToBeRead = bufferedReader.readLine()) != null) {
       // userInfo = lineToBeRead.split(",");
       // String userName = userInfo[0].trim();
       // String hashP = userInfo[1].trim();
       // String pw = userInfo[2].trim();
       // String position = userInfo[3].trim();
       //
       // UserInfo user = new UserInfo(userName, hashP, pw, position);
       // users.add(user);
       // }

   }
}

UserInfo.java


public class UserInfo {
private String userName;
private String hash;
private String passWord;
private String position;

public UserInfo(String userName, String hash, String passWord, String position) {
   super();
   this.userName = userName;
   this.hash = hash;
   this.passWord = passWord;
   this.position = position;
}

public String getUserName() {
   return userName;
}

public void setUserName(String userName) {
   this.userName = userName;
}

public String getHash() {
   return hash;
}

public void setHash(String hash) {
   this.hash = hash;
}

public String getPassWord() {
   return passWord;
}

public void setPassWord(String passWord) {
   this.passWord = passWord;
}

public String getPosition() {
   return position;
}

public void setPosition(String position) {
   this.position = position;
}

}

MD5.java

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
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote