/* This program is set up to check passwords, and to either verify and allow one into the class list - for inls161. The password and userName are "java" and "inls161" repectively. I added a bit to the request of the assignment in that I added in the ability to repeat attempts to try the password /user combination. There is different messages based on the number of tries. In addition further warning when you have a last try to get it right is given Possible further add-ins for this program include a different reply if the first time they miss password and then miss userName second time and vice-versa. In addition, some kind of additional programming to protect input of userName from being displayed */ //import classes import javax.swing.*; // names the program, sets up JApplet public class Assignment4a extends JApplet { // begins the init method public void init() { // this step defines variables that will be used in this program String userName; String password; int counter = 0 ; /* this allows a limited number of checks of the password (<3) before later instructions deny the user any further attempts */ while ( counter < 3 ) { /* gathers input from user by using JOptionPane.showInputDialog method - in addition to this, will give different outputs for each successful try. This goes beyond what is required by providing a */ userName = JOptionPane.showInputDialog ("Please input class name:"); password = JOptionPane.showInputDialog ("Please input password:"); // outcome for the user getting the right name and password if ((userName.equals("inls161")) && (password.equals("java") && counter == 0)) {JOptionPane.showMessageDialog (null, "You are welcome to the INLS161 java class."); break;} // outcome for the user getting the right name and password on 2nd attempt if ((userName.equals("inls161")) && (password.equals("java") && counter == 1)) {JOptionPane.showMessageDialog (null, "It took a 2nd attempt to get this right!! - You are welcome to the INLS161 java class."); break;} // outcome for the user getting the right name and password on third attempt if ((userName.equals("inls161")) && (password.equals("java") && counter == 2)) {JOptionPane.showMessageDialog (null, "Wow, it took 3 Attempts to get this right, please remember your password more carefully!! - You are welcome to the INLS161 java class."); break;} // if user does not get something right the following outcomes result // second attempt at user name and password!! if (((!userName.equals("inls161")) && (password.equals("java")) && ( counter == 0 ))) {JOptionPane.showMessageDialog (null, "Wrong userName, \n try again, please."); } if (((userName.equals("inls161")) && (!password.equals("java"))) && ( counter == 0 )) {JOptionPane.showMessageDialog (null, "Wrong password, \n try again, please."); } if (((!userName.equals("inls161")) && (!password.equals("java"))) && (counter == 0 )) {JOptionPane.showMessageDialog (null, "Please check your userName and password, \n then try again"); } // if user does not get something right again the following outcomes result // third attempt at user name and password!! if (((!userName.equals("inls161")) && (password.equals("java"))) && (counter == 1 )) {JOptionPane.showMessageDialog (null, "Wrong userName this time, one last chance to try again"); } if (((userName.equals("inls161")) && (!password.equals("java"))) && (counter == 1 )) {JOptionPane.showMessageDialog (null, "Wrong password this time, one last chance to try again"); } if (((!userName.equals("inls161")) && (!password.equals("java"))) && (counter == 1 )) {JOptionPane.showMessageDialog (null, "Please check your userName and password this time, one last chance to try again"); } // this step adds a number to the counter in order to discontinue on earlier while command (<3) counter = counter + 1; }// ending bracket for the while loop /*If the user failed to login for three times, tell him that he can't login after 3 failed attempts */ if (counter == 3) {JOptionPane.showMessageDialog(null, "Sorry, you have failed 3 times.\n You are being disconnected - check userName and passowrd and try again"); } } //end method } //end class Homework3