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

Option 1: Authentication System For security-minded professionals, it is importa

ID: 3598211 • Letter: O

Question

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 How do I write this code to include 2 classes and read the credentials.txt file that I have and also print out the role of the user by accessing the role files that I have in NetBeans?

Here are the input files that I have.

The credentials.txt is this:

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

The role files are these:

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.

veterinarian.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, current treatments/illnesses (if any), and maintain a vaccination log.

zookeeper.txt:

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.

Explanation / Answer

//import statements

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.util.Scanner;

//Create a class Authentication

public class Secretproc

{

// main() method

public static void main(String[] args) throws IOException

{

// Call loginScreen() method

loginScreen();

}

// loginScreen() method for user login

public static void loginScreen()

{

// Declare variables

String genPwd = "";

int flag = 0, attempts = 3;

// Create an object 'br' for BufferedReader class to accept data from

// user and read data from a file

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println(" Login");

try {

do {

attempts--;

System.out.println("Enter Username");

String uName = br.readLine();

System.out.println("Enter Password");

String pwd = br.readLine();

// Create the object 'md' for the MessageDigest class to convert

// password in md5

MessageDigest md = MessageDigest.getInstance("MD5");

md.update(pwd.getBytes());

byte[] bytes = md.digest();

// Create the object for String

StringBuilder sb = new StringBuilder();

for (int j = 0; j < bytes.length; j++)

{

sb.append(Integer.toString((bytes[j] & 0xff) + 0x100, 16).substring(1));

}

genPwd = sb.toString();

//System.out.println("Password entered by you:" + genPwd);

String currentLine;

// Open credentials.txt file

BufferedReader bin = new BufferedReader(new FileReader("credentiail.txt"));

// Check the username and password from the file

// Read the each line from the file

while ((currentLine = bin.readLine()) != null)

{

// Split the line where the tab is present

String[] arr = currentLine.split(" ");

// Check username

if (arr[0].equals(uName))

{

// Check password

if (arr[1].equals(genPwd))

{

flag = 1;

break;

}

}

}

// Checks if the user enters more then 3 attempts

if (attempts == 0)

{

System.out.println("You are attempted to login more then three times");

System.out.println("Exiting...");

System.exit(1);

}

// If username and password is true

if (flag == 1)

{

// Call adminScreen() method

adminScreen();

break;

}

// If invalid username and password

else

{

System.out.println("Invalid Username or Password.");

System.out.println("Please try again.");

System.out.println(attempts + " more attemptes left. ");

}

} while (attempts>0);

}

catch (NoSuchAlgorithmException e)

{

e.printStackTrace();

}

catch (IOException e)

{

e.printStackTrace();

}

}

// Create adminScreen() method

public static void adminScreen()

{

String logOut;

// Create Scanner class object to accept data from the user

Scanner sc = new Scanner(System.in);

System.out.println(" Welcome Admin");

System.out.println("Press 999 for log out ");

// Accept data from the user

do

{

logOut = sc.nextLine();

} while (!logOut.equals("999"));

// If the user want to exit from admin screen

if (logOut.equals("999"))

{

// Call login screen

loginScreen();

}

}

}

1. Process Documentation: Process documentation containing all of the following elements:

A. Problem Statement/Scenario: Class Secretproc is defined to solve the problem. Problem is to make an authorized system for login. If username and password will be matched only then a user can login the system.

B. Overall Process: Problem is divided into further methods. Like a method named adminScreen() to welcome the admin of the system and to display the welcome message.

Another method loginScreen() to read the username and password from the file and read the filenames and match by the username and password entered by the user.

C. Pseudocode: Whole program is breakdown into different methods of the class.

loginScreen() method to get login in the system. For login user has to match the username and password entered by the user to the data stored in the credential.txt file.
adminScreen() method to display the message on the screen when user get login in the system.
Main() method to call other methods of the class.
D. Methods and Classes: class Secretproc is there that is used in the program.

Methods used in the program are loginScreen() and adminScreen() and main method.

E. Error Documentation: Errors can be occurred if file would not be created correctly.

F. Solution Documentation: Solution Document gives all the output of the program and that will be error-free.

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