Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment, you will implement a UserManagement class. The UserManagement class should implement the UserManagementInterface. The interface is provided in your workbench, and the

In this assignment, you will implement a UserManagement class. The UserManagement class should implement the UserManagementInterface. The interface is provided in your workbench, and the requirements for each method are listed.

Other requirements for UserManagement class include:

  • In login, when the username exists, always increment the success counter or failed counter based on whether or not the password matches the user's password.
  • Change the password always reset the counts for both the success login and failed login.
  • The display should display the overall statistics and then all the user information based on the alphabetical order of the username. The format for displaying each user is
    username hashed_password success_login_count failed_login_count
    Display each user on a separate line.
  • Please refer to the two test cases for the exact output.

In practice, the password should not be stored as plaintexts. A method messageDigest is provided in the UserManagementInterface so that you can simply call the method to get the hashed form of the password. Password comparisons should be based on hashed values.

UserManagementInterface

import java.util.Base64; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException;

/** * In your implementation, make sure that you don't store the original * password in the list. Instead, hash the password first, before you store * the information into an user object. When you need to login, hash the * password word, and then compare the hashed value with the password * information in a user object. That's how passwords are handled in * really world applications. * * For your convenience, the messageDigest method below hashes a String. * */

public interface UserManagementInterface { // add a user with the name and password to a manager // if the username is not also in the manager, adds the user in // and returns true. Otherwise, returns false. Please note that // the password will not change if the username is already present. boolean userAdd(String username, String password);

// change the password for a user. // the username must be present, and the old password must match // the existing user's password(hashed) // return true if the change is successful, and false otherwise. boolean changePassword(String username, String old, String nx);

// login the user based on the username and password // you need to check the presence of the username // and then check whether or not the password is equal // to the stored password(both values should be hashed for // comparison purpose) boolean login(String username, String password);

// display all the users in the list ordered by the usernames // in ascending order // the username, password, successfullogin // and failedlogin should be separated by one space void display();

// you just need to know how to use the following method default String messageDigest(String str) { String hash = null; try { MessageDigest md = MessageDigest.getInstance("SHA-256");

md.update(str.getBytes("UTF-8")); byte raw[] = md.digest();

hash = new String(Base64.getEncoder().encodeToString(raw));

} catch (NoSuchAlgorithmException e) {

} catch (UnsupportedEncodingException e) {

}

return hash; } }

Sample Input

A zach 123 A john passwd1 A alice pass2 D L zach 123 L kathy 123 L zach 1234 D Q 

Sample Output

true true true Total successful login: 0 total failed login: 0 alice G6PRbpiBlZ+MmpdihU9yxuYyHN1ENYoQpOk5AzEX6rk= 0 0 john Ox1+mnw3FBNQ+0c/oJm4sYAwzeGQnzY+N1jlLU6hp7Q= 0 0 zach pmWkWSBCL51Bfkhn79xPuKBKHz//H6B+mY6G9/eieuM= 0 0 true false false Total successful login: 1 total failed login: 2 alice G6PRbpiBlZ+MmpdihU9yxuYyHN1ENYoQpOk5AzEX6rk= 0 0 john Ox1+mnw3FBNQ+0c/oJm4sYAwzeGQnzY+N1jlLU6hp7Q= 0 0 zach pmWkWSBCL51Bfkhn79xPuKBKHz//H6B+mY6G9/eieuM= 1 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions