Question

In: Computer Science

URGENT JAVA Develop a Java computer program to simulate access control to a system network. The...

URGENT JAVA

Develop a Java computer program to simulate access control to a system network. The username and password authentication mechanism is used as an access control mechanism in this project. The program needs to authenticate the user with their username and hashed password stored in Access Manager User (AMU) file. To create an Access Manager User file, you need to develop a java program that takes username and password as input and then generates a file containing the username, hashed password, and plaintext password. In real world, the plaintext are not saved in the AMU file. However, you need the username and corresponding plaintext password for testing of your main program. The structure of the AMU file is shown in the appendix. Note that this should be done as a separate program. The main program operates in the following manner. It first prompts the user to enter username and password. After the user enters both username and password, it hashes the password and search the AMU file to verify both the user name and password. If the program verifies the username and password, it returns the message “Access Granted.” If the programcould not verify the username, it returns the message “Access Denied. You are not a registered user.” If the program verifies the username but not the password, it prompts the user to enter the password again. If the user enter the password three times incorrectly, the system locks the user account and gives this message. “You exceeded entering the allowablenumber of incorrect password. Your account is locked. Contact system administrator to unlock your account”

Solutions

Expert Solution

import java.io.*;  

import java.util.Scanner;

public class loginValidation {

public static void main(String[] args) {

// To add credentials call as below

// addCredentials("userName", "Password");

  

try {

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

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

String useerName;

useerName = reader.readLine();

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

String password = reader.readLine();

System.out.println(validateUserCredentials(useerName, password));

} catch (IOException e) {

e.printStackTrace();

}

}

public static String validateUserCredentials(String userName, String password) {

  

try {

File myObj = new File("amu.txt");

Scanner myReader = new Scanner(myObj);

while (myReader.hasNextLine()) {

String data = myReader.nextLine();

String[] userData = data.split(";");

if(userData[0].equals(userName)) {

if(userData[1].equals(String.valueOf(password.hashCode()))) {

return "Access Granted";

}

else {

try {

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

int i = 0;

while (!userData[1].equals(String.valueOf(password.hashCode())) && i < 3) {

System.out.println("Incorrect Password, Enter Again: ");

password = reader.readLine();

i++;

}

if( i == 3) {

return "You excedeed entering the allowiable no.of incorrect password, your account is locked. contact system administrator to unlock account";

}

else {

return "Access Granted";

}

} catch (IOException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

  

}

}

}

myReader.close();

} catch (FileNotFoundException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

  

return "Access Denied. You are not a registered user";

}

public static void addCredentials(String userName, String password) {

try

{

File myObj = new File("amu.txt");

if (myObj.createNewFile()) {

System.out.println("File created: " + myObj.getName());

}

String writeData = userName + ";" + password.hashCode() + ";" + password + "\n";

BufferedWriter out = new BufferedWriter(new FileWriter("amu.txt", true));

out.write(writeData);

out.close();

} catch (IOException e) {

System.out.println("An error occurred.");

e.printStackTrace();

}

}

}


Related Solutions

Develop a simple GUI-based Java program that may be used to control a lighting system
Develop a simple GUI-based Java program that may be used to control a lighting system
In reference to network access control, describe some of the access control mechanism used by a...
In reference to network access control, describe some of the access control mechanism used by a network administrator to filter, inspect and detect different forms of traffic.
In Java, C, C++ or Python Develop a simulation program to simulate an 8-port Ethernet switch....
In Java, C, C++ or Python Develop a simulation program to simulate an 8-port Ethernet switch. The switch initially has no knowledge about the hosts connected to each port. It learns frame addresses and stores-and-forwards the frames. The input text file "in.txt" contains information of the incoming frames, one frame per line. There are 4 pieces of data per line: frame ID, arrival port, frame source address, and frame destination address. The frames arrive at the switch in the order...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery...
Java 176 Lottery Program in Word. Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line. The...
Develop a Java application to simulate a game played in an elementary classroom. In this game,...
Develop a Java application to simulate a game played in an elementary classroom. In this game, the teacher places herself in the center of a circle of students surrounding her. She then distributes an even number of pieces of candy to each student. Not all students will necessarily receive the same number of pieces; however, the number of pieces of candy for each student is even and positive. When the teacher blows a whistle, each student takes half of his...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
It is required to install a new computer control system. This new computer control system could...
It is required to install a new computer control system. This new computer control system could be purchased at a cost of $125,000. The project working life of this system is 05 years with a salvage value of $50,000. The working capital investment is $23,331 for this project. The annual labor savings due to this project will be $100,000. Additional annual expenses involve labor expense of $20,000, Material expense of $12,000 & Overhead expense of $8,000. Use Straight Line Depreciation...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers...
Java: Using ArrayLists to Simulate a Lottery Program Simulate a Lottery Drawing by choosing 7 numbers at random from a pool containing 30 numbers Each time a number is selected, it is recorded and removed from the pool The pool values are 00 to 29 inclusive Your program must output each selected number from the drawing using a two-digit format. For Example, the number 2 would be represented by 02 on the “Picked” line.    The numbers drawn cannot repeat Sort...
For Network Access Control and Cloud Security You are required to research and report on this...
For Network Access Control and Cloud Security You are required to research and report on this topic according to the Detail of Question below. A. Select one paper to: Read, understand in order to present three main parts: 1. Summary: o Provide a 200-300 word summary of the paper under review, from the background to the results being presented, and further work proposed. Please do NOT copy the abstract into this space! 2. Main points: o The main issues as...
How do the IEEE 802.1x standards improve network access control?
How do the IEEE 802.1x standards improve network access control?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT