Question

I need help ASAP on this, this is due at midnight PST. This is the current...

I need help ASAP on this, this is due at midnight PST. This is the current code I have. How can I allow the user to quit. My counting while loop works fine, but I would like it to not keep outputting username if a file was successfully opened.

This is what is required.

Prompt
You have assumed the role of managing the technology infrastructure at a zoo. You will develop a working program (either an authentication system or a monitoring system) for the zoo designed to follow the specifications outlined in the overview. You will also provide detailed documentation describing your development process. Select from one of the following options as the basis of your program.
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.

This is my java code:

package finalproject;


import java.util.Scanner; //importing scanner
import java.io.BufferedReader; //importing buffered reader
import java.io.InputStreamReader; //importing input stream reader
import java.security.MessageDigest; //importing message digest
import java.io.IOException; //importing java io exception
import java.io.*;
import java.security.NoSuchAlgorithmException;


class MD5Digest { //MD5 digest class
public static void MD5Digest(String original) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5"); //get md5 digest
md.update(original.getBytes()); //updating password
byte[] digest = md.digest(); //MD5 digested password
  
StringBuffer sb = new StringBuffer(); //initializing string buffer
for (byte b: digest) {
sb.append(String.format("%02x", b & 0xff)); //appending string
}
boolean correct = true;
  
  
System.out.println("original:" + original); //original string
   System.out.println("digested:" + sb.toString()); //sb.toString() is what you'll need to compare password strings
}
}

public class FinalProject {


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

  
boolean correct = false;
BufferedReader scnr = new BufferedReader(new InputStreamReader(System.in));
//new buffered reader input stream reader
String username = null;
String password = null;
  
int counter = 0;
  
while (counter < 3) { //counter for 3 attempts
counter++;


System.out.println("Enter q to quit");
System.out.println();
System.out.println("Username: "); //prompt for username
username = scnr.readLine(); //reading input
System.out.println("Password: "); //prompt for password
password = scnr.readLine(); //reading input


  
if ((username.equals("griffin.keyes")) && (password.equals("alphabet soup"))) {
//checking usename and password are correct
//output approriate file
System.out.println("Hello, Zookeeper!\n" + "\n" +
"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();
System.out.println("");
}
  
else if ((username.equals("bruce.grizzly")) && (password.equals("M0nk3y business"))){
//checking usename and password are correct   
//output approriate file
System.out.println("Hello, Zookeeper!\n" + "\n" +
"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.");
}
  
else if ((username.equals("bernie.gorilla")) && (password.equals("secret password"))) {   
//checking usename and password are correct   
//output approriate file
System.out.println("Hello, Veterinarian!\n" + "\n" +
"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.");
}
  
else if ((username.equals("jerome.grizzlybear")) && (password.equals("grizzly1234"))) {   
//checking usename and password are correct
//output approriate file
System.out.println("Hello, Veterinarian!\n" + "\n" +
"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.");
}
  
else if ((username.equals("rosario.dawson")) && (password.equals("animal doctor"))) {
//checking usename and password are correct   
//output approriate file
System.out.println("Hello, System Admin!\n" + "\n" +
"As administrator, you have access to the zoo's main computer system."
+ " This allows you to monitor users in the system and their roles.");
  
}
  
else if ((username.equals("bruce.grizzlybear")) && (password.equals("letmein"))) {
//checking usename and password are correct   
//output approriate file
System.out.println("Hello, System Admin!\n" + "\n" +
"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("You have exceeded the number of login attempts or chosen to exit");

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************FinalProject.java**************************/

import java.io.BufferedReader; //importing buffered reader
import java.io.IOException; //importing java io exception
import java.io.InputStreamReader; //importing input stream reader
import java.security.MessageDigest; //importing message digest

class MD5Digest { // MD5 digest class
   public static void MD5Digest(String original) throws Exception {
       MessageDigest md = MessageDigest.getInstance("MD5"); // get md5 digest
       md.update(original.getBytes()); // updating password
       byte[] digest = md.digest(); // MD5 digested password

       StringBuffer sb = new StringBuffer(); // initializing string buffer
       for (byte b : digest) {
           sb.append(String.format("%02x", b & 0xff)); // appending string
       }
       boolean correct = true;

       System.out.println("original:" + original); // original string
       System.out.println("digested:" + sb.toString()); // sb.toString() is what you'll need to compare password
                                                           // strings
   }
}

public class FinalProject {

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

       BufferedReader scnr = new BufferedReader(new InputStreamReader(System.in));
       // new buffered reader input stream reader
       String username = "";
       String password = "";

       int counter = 0;

       while (counter < 3) { // counter for 3 attempts
           counter++;

           System.out.println("Enter q to quit");
           System.out.println();

           System.out.println("Username: "); // prompt for username
           username = scnr.readLine(); // reading input
           if (username.equalsIgnoreCase("q")) {

               break;
           }
           System.out.println("Password: "); // prompt for password
           password = scnr.readLine(); // reading input

           if ((username.equals("griffin.keyes")) && (password.equals("alphabet soup"))) {
               // checking usename and password are correct
               // output approriate file
               System.out
                       .println("Hello, Zookeeper!\n" + "\n" + "As zookeeper, you have access to all of the animals'\n"
                               + "information and their daily monitoring logs.\n"
                               + "This allows you to track their feeding habits,\n"
                               + " habitat conditions, and general welfare.");
               System.out.println();
               System.out.println("");
           }

           else if ((username.equals("bruce.grizzly")) && (password.equals("M0nk3y business"))) {
               // checking usename and password are correct
               // output approriate file
               System.out
                       .println("Hello, Zookeeper!\n" + "\n" + "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.");
           }

           else if ((username.equals("bernie.gorilla")) && (password.equals("secret password"))) {
               // checking usename and password are correct
               // output approriate file
               System.out.println("Hello, Veterinarian!\n" + "\n"
                       + "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.");
           }

           else if ((username.equals("jerome.grizzlybear")) && (password.equals("grizzly1234"))) {
               // checking usename and password are correct
               // output approriate file
               System.out.println("Hello, Veterinarian!\n" + "\n"
                       + "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.");
           }

           else if ((username.equals("rosario.dawson")) && (password.equals("animal doctor"))) {
               // checking usename and password are correct
               // output approriate file
               System.out.println("Hello, System Admin!\n" + "\n"
                       + "As administrator, you have access to the zoo's main computer system."
                       + " This allows you to monitor users in the system and their roles.");

           }

           else if ((username.equals("bruce.grizzlybear")) && (password.equals("letmein"))) {
               // checking usename and password are correct
               // output approriate file
               System.out.println("Hello, System Admin!\n" + "\n"
                       + "As administrator, you have access to the zoo's main computer system."
                       + " This allows you to monitor users in the system and their roles.");

           } else {

               System.out.println("Incorrect password! Try again....");
           }

       }
       System.out.println("You have exceeded the number of login attempts or chosen to exit");
   }
}
/**************************output***************************/

Enter q to quit

Username:
abc
Password:
abc
Incorrect password! Try again....
Enter q to quit

Username:
griffin.keyes
Password:
alphabet soup
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.


Enter q to quit

Username:
q
You have exceeded the number of login attempts or chosen to exit
Console x <terminated> FinalProject [Java Application] C:\Program Files\Java\jre1.8.0_211\bin\javaw.exe (Aug 19, 2019, 10:53:

Please let me know if you have any doubt or modify the answer, Thanks :)

Add a comment
Know the answer?
Add Answer to:
I need help ASAP on this, this is due at midnight PST. This is the current...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Netbeans code Option 1: Authentication System For security-minded professionals, it is important that only the...

    Java Netbeans code 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...

  • Option 1: Authentication System For security-minded professionals, it is important that only the appropriate people gain...

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

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • Written in Java I have an error in the accountFormCheck block can i get help to...

    Written in Java I have an error in the accountFormCheck block can i get help to fix it please. Java code is below. I keep getting an exception error when debugging it as well Collector.java package userCreation; import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.regex.Matcher; import java.util.regex.Pattern; import javafx.event.ActionEvent; import javafx.fxml.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.text.Text; import javafx.stage.*; public class Controller implements Initializable{ @FXML private PasswordField Password_text; @FXML private PasswordField Confirm_text; @FXML private TextField FirstName_text; @FXML private TextField LastName_text;...

  • Can someone fix the program below so it does what the picture says it won't work...

    Can someone fix the program below so it does what the picture says it won't work for me. import java.util.Scanner; public class Userpass { static String arr[]; static int i = 0; public static void main(String[] args) { String username, password; int tries = 0, result; do { System.out.print("Enter the username: "); username = readUserInput(); System.out.print("Enter the password: "); password = readUserInput(); result = verifyCredentials(username, password); tries++; if (result == -1) System.out.println("The username is incorrect!\n"); else if (result == -2)...

  • You need to implement a web application that is split in three parts, namely, Webpage, PHP and My...

    You need to implement a web application that is split in three parts, namely, Webpage, PHP and MySQL. Each of them will be used accordingly to solve a simple problem described below. Remember to implement the logic in the most secure way of your knowledge. PHP Implement a PHP function that reads in input a string from the user and store it in a table (e.g., in a field called "Content Name"). The function should be able to read the...

  • Hi I need some help writing a security code using python mongodb restful api. I just...

    Hi I need some help writing a security code using python mongodb restful api. I just need help on how to provide a security login to user to enter their username and password or to have a block in using extra access once they have logined and they want more access to the databases they will be force to sign out of the server but I just do not know how to start on it can someone show me how...

  • Hey Guys , I need help with this assignment: This component of the final exam will...

    Hey Guys , I need help with this assignment: This component of the final exam will have two data structures. The two data structures will be a stack and the other will be a hashmap. The hashmap object will be added to the stack every time the user picks an answer. The hashmap will have a key and value. The key will be the timestamp (system time when the user selected a choice) and the value will be the choice...

  • Requirements I have already build a hpp file for the class architecture, and your job is to imple...

    Requirements I have already build a hpp file for the class architecture, and your job is to implement the specific functions. In order to prevent name conflicts, I have already declared a namespace for payment system. There will be some more details: // username should be a combination of letters and numbers and the length should be in [6,20] // correct: ["Alice1995", "Heart2you", "love2you", "5201314"] // incorrect: ["222@_@222", "12306", "abc12?"] std::string username; // password should be a combination of letters...

  • Hey I really need some help asap!!!! I have to take the node class that is...

    Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT