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

I this code to be fixed and writing other classes to finish the project. Ok i am

ID: 3589879 • Letter: I

Question

I this code to be fixed and writing other classes to finish the project.

Ok i am try to write a program that gets an input from a user to sign into a comptuer. This connected to a zoo network of computer system. Below is what class wants from us. The java program that is below the project description is what i have done so far. I can not figure out what is wrong with the program. THe has to check a if a userID password and pin number is right.

For your development project, you will imagine you are in charge of managing a zoo’s computer infrastructure. There are many aspects of a zoo that need to be in place to keep it running. Two of those aspects are controlling data access and monitoring animal activities in exhibits. You will select which of these key components you wish to develop. Both options require at least two classes and for the design to be broken into multiple methods. Select one of the optionsprovided in the prompt below and create your program and process documentation based on the specified requirements.The final project for this course is the creation of an authentication or monitoring system. The final project represents anauthentic demonstration ofcompetency becauseit involves application of real world Java programming. The project is divided into one milestone and several final projectjournal assignments, which will be submitted at various points throughout the course to scaffold learning and ensure quality final package

userpass;

import java.io.FileInputStream;
import java.security.MessageDigest;
import java.util.Scanner;


public class userpass {
   public static void main(String[] args) throws Exception {
      
      Scanner scnr = new Scanner(System.in);
      FileInputStream admin = null; //file input streams
      FileInputStream zookeeper = null;
      FileInputStream veterinarian = null;
      
      
        //create array based on credentials.txt
      final int NUM_ELEMENTS = 6;
      String[] storedUser = new String[NUM_ELEMENTS];
      String[] role = new String[NUM_ELEMENTS];
      String[] hashPassword = new String[NUM_ELEMENTS];
      String user = "";
      String pass = "";
      String hash = "";
      userRoles userInput = new userRoles();
      String userRole = "";
      int i = 0; //loop variable
      int j = 0; //loop variable
      int user = 0;
      boolean verified = false;
      
        //populate username/password array
      storedUser[i] = "Todd.Baker";      hashPassword[i] = "108de81c31bf9c622f76876b74e9285f"; ++i;
      storedUser[i] = "Tim.Smith";     hashPassword[i] = "3e34baa4ee2ff767af8c120a496742b5"; ++i;
      storedUser[i] = "Tommy.Coffemen";     hashPassword[i] = "a584efafa8f9ea7fe5cf18442f32b07b"; ++i;
      storedUser[i] = "Luke.Skywalker";      hashPassword[i] = "17b1b7d8a706696ed220bc414f729ad3"; ++i;
      storedUser[i] = "leai.Skywalker"; hashPassword[i] = "3adea92111e6307f8f2aae4721e77900"; ++i;
      storedUser[i] = "Jammy.Smith"; hashPassword[i] = "0d107d09f5bbe40cade3de5c71e9e9b7"; ++i;
      
        //display usage information for user
      System.out.prin(null, "All entries are case sensitive. " +
                "Enter "quit" at any time to exit.", "Authentication System");
      
            //prompt user for credentials
      user = (String)(null, "Enter username: ", "Authentication System");
      if (user.equals("quit")){
         System.out.print(null, "You have chosen to exit. Goodbye.", "Authentication System");
         return;
      }
      pass = (String)(null, "Enter password: ", "Authentication System");
      if (passw.equals("quit")){
         System.out.print(null, "You have chosen to exit. Goodbye.", "Authentication System");
         return;
      }
      
            //check user credentials no more than 3 times
      for (i = 0; i < 3; ++i){
              
                //compare user credentials to storedUsername and convert password
         for (j = 0; j < NUM_ELEMENTS; ++j) {      
            if (user.equals(storedUser[j])){
               String original = pass; //provided MD5Digest code
               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));
               }
                      
               verified = true;
               user = j;
               hash = sb.toString();
            }
         }
         
                      
                        //user credentials verified
         else {
            userInput.setUser(user); //set username
            userRole = userInput.getRole(); //find corresponding role for user
            userInput.printWelcome(); //display welcome message to user
       
            break;
                              
         }
      }
   }
}
  
   

Explanation / Answer

package zoo;

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;

import java.util.ArrayList;

import java.util.List;

public class Application {

private static List<User> users;

static {

users = new ArrayList<>();

users.add(new User("Todd.Baker", "108de81c31bf9c622f76876b74e9285f", ""));

users.add(new User("Tim.Smith", "3e34baa4ee2ff767af8c120a496742b5", ""));

users.add(new User("Tommy.Coffemen", "a584efafa8f9ea7fe5cf18442f32b07b", ""));

users.add(new User("Luke.Skywalker", "17b1b7d8a706696ed220bc414f729ad3", ""));

users.add(new User("leai.Skywalker", "3adea92111e6307f8f2aae4721e77900", ""));

users.add(new User("Jammy.Smith", "0d107d09f5bbe40cade3de5c71e9e9b7", ""));

// change if you want to read data from property file or text file

// accordingly here.

}

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

// display usage information for user

System.out.println("All entries are case sensitive. " + "Enter "quit" at any time to exit "

+ "Authentication System ");

String userName = null;

String userPassword = null;

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

System.out.print("Enter username: ");

userName = br.readLine();

if (userName.equals("quit")) {

System.out.println("You have chosen to exit. Goodbye. ");

return;

}

System.out.print("Enter password: ");

userPassword = br.readLine();

if (userPassword.equals("quit")) {

System.out.println("You have chosen to exit. Goodbye. ");

return;

}

User user = Application.authenticate(userName, userPassword);

if (user != null) {

System.out.println("Welcome ");

} else {

System.out.println("User does not exists! ");

}

}

public static User authenticate(String userName, String password) {

// check user credentials no more than 3 times

for (int i = 0; i < 3; ++i) {

// compare user credentials to storedUsername and convert password

for (User user : users) {

if (userName.equals(user.getName())) {

MessageDigest md = null;

try {

md = MessageDigest.getInstance("MD5");

} catch (NoSuchAlgorithmException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

md.update(password.getBytes());

byte[] digest = md.digest();

StringBuffer sb = new StringBuffer();

for (byte b : digest) {

sb.append(String.format("%02x", b & 0xff));

}

if (user.getPassword().equals(sb.toString())) {

return user;

}

}

}

}

return null;

}

}

package zoo;

public class User {

private String name;

private String password;

private String role;

public User(String name, String password, String role) {

this.name = name;

this.password = password;

this.role = role;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getRole() {

return role;

}

public void setRole(String role) {

this.role = role;

}

}