Question: I need help with this authentication system assignment. The program needs to request a user nameand verify a password. the user must be given 3

I need help with this authentication system assignment. The program needs to request a user nameand verify a password. the user must be given 3 attempts to enter a passwod prior to closing the session. the prorgam wil continue to ask for user name and password until the user enters q to close the program.

Below is my code

import java.util.Scanner;

public class AuthenticationSystem {

public static void main(String[] args) {

String userNames = null; String userPassword = null;

// TODO code application logic here boolean quit = false; Scanner scnr = new Scanner(System.in); System.out.println("Welcome user! Press q to quit at anytime."); do { System.out.println("Please enter Your Username: "); userNames = scnr.nextLine(); if(userNames != null){ if(userNames.length() == 1 && userNames.equalsIgnoreCase("q")) { quit = true; } else if (userNames.contains("amy.lee") || userNames.contains("rose.moore")||userNames.contains("chris.kelly") { System.out.println("Welcome User!"); System.out.println("Please enter your password"); userPassword = scnr.nextLine(); if(userPassword != null){ int passwordAttempts = 0; while(userPassword !="password1" || userPassword!="password2" || userPassword != "password3" && passwordAttempts < 3){ if (userPassword !="password"){ System.out.println("Please try again."); userPassword = scnr.nextLine(); }else { System.out.println("Too many password attempts. Session Terminated"); } } while (!quit); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!