while true enter your username String username

While true enter your username string username

This preview shows page 2 - 4 out of 5 pages.

while (true) { System.out.print("Please enter your username: "); String username = userInputScanner.nextLine(); System.out.print("Please enter your password: "); String password = userInputScanner.nextLine(); // Prompt the user for login information System.out.println(); boolean valid = isValidLogin(username, password); // Checks validity of login credentials if (valid) { sessionScreen(username, userInputScanner); // Allow the user access to sessionScreen } else { System.out.println("Sorry that login information was incorrect\n"); } } } /** * This is the method where a logged in user is able to run the access control commands * @param username is the string object that contains the username of a user * @param userInputScanner scanner object to read input from user */ public void sessionScreen(String username, Scanner userInputScanner) { setCurrentUser(username); while (currentUser != null) { System.out.println("Please enter one of the following commands\nSeparate usernames, " + "passwords, and commands with single space"); System.out.print("1) logout\n" + "2) newpw [newpassword]\n" + "3) adduser [username]\n" + "4) adduser [username] [true or false]\n" + "5) rmuser [username]\n" + "6) giveadmin [username]\n" + "7) rmadmin [username]\n" + "8) resetpw [username]\n\nEnter Command: "); // Give the user a list of all the functions within the access control software String input = userInputScanner.nextLine().trim(); // Trims any whitespace from any input String[] inputArray = input.split(" "); // Split the input into an array and use it to run the proper command with the proper inputs if (inputArray[0].trim().equalsIgnoreCase("logout")) { logout(); } else if (inputArray[0].equalsIgnoreCase("newpw")) { changePassword(inputArray[1]); } else if (inputArray[0].equalsIgnoreCase("adduser") && inputArray.length == 2) { addUser(inputArray[1]); } else if (inputArray[0].equalsIgnoreCase("adduser") && inputArray.length == 3) { boolean isAdmin = Boolean.parseBoolean(inputArray[2].trim()); addUser(inputArray[1], isAdmin); } else if (inputArray[0].equalsIgnoreCase("rmuser")) { removeUser(inputArray[1]); } else if (inputArray[0].equalsIgnoreCase("giveadmin")) { giveAdmin(inputArray[1]); } else if (inputArray[0].equalsIgnoreCase("rmadmin")) { takeAdmin(inputArray[1]);
Image of page 2
} else if (inputArray[0].equalsIgnoreCase("resetpw")) { resetPassword(inputArray[1]); } else { System.out.println("\nYour input does not match a valid
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '19
  • Login, partner, public class AccessControl

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes