Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Password_DiljotJ_R1 {
- public static void main(String[] args) {
- int attempt = 0;
- String username = "john";
- String password = "123";
- String usernameEntered;
- String passwordEntered;
- usernameEntered = (JOptionPane.showInputDialog("Please enter the username"));
- passwordEntered = (JOptionPane.showInputDialog("Please enter the password"));
- if (usernameEntered.equals(username) && passwordEntered.equals(password) ){
- JOptionPane.showMessageDialog(null,"Credentials Match. Welcome John!");
- }
- else if (usernameEntered.equals(username)) {
- JOptionPane.showMessageDialog(null,"Password Invalid.");
- attempt++;
- passwordEntered = (JOptionPane.showInputDialog("Please enter the password AGAIN"));
- }
- else if (passwordEntered.equals(password)) {
- JOptionPane.showMessageDialog(null, "Username Invalid.");
- attempt++;
- usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
- }
- else {
- JOptionPane.showMessageDialog(null,"Both username and password are inncorrect. Who are you");
- attempt++;
- usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
- passwordEntered = (JOptionPane.showInputDialog("Please enter password AGAIN"));
- }
- if (attempt == 5){
- JOptionPane.showMessageDialog(null,"You've reached maximum attempts. Program will now close");
- }
- }
- }
- int attempt = 0;
- String username = "john";
- String password = "123";
- String usernameEntered;
- String passwordEntered;
- usernameEntered = (JOptionPane.showInputDialog("Please enter the username"));
- passwordEntered = (JOptionPane.showInputDialog("Please enter the password"));
- if (usernameEntered.equals(username) && passwordEntered.equals(password) ){
- JOptionPane.showMessageDialog(null,"Credentials Match. Welcome John!");
- }
- if (attempt == 5){
- JOptionPane.showMessageDialog(null,"You've reached maximum attempts. Program will now close");
- break;
- }
- else if (usernameEntered.equals(username)) {
- JOptionPane.showMessageDialog(null,"Password Invalid.");
- attempt++;
- passwordEntered = (JOptionPane.showInputDialog("Please enter the password AGAIN"));
- }
- else if (passwordEntered.equals(password)) {
- JOptionPane.showMessageDialog(null, "Username Invalid.");
- attempt++;
- usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
- }
- else {
- JOptionPane.showMessageDialog(null,"Both username and password are inncorrect. Who are you");
- attempt++;
- usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
- passwordEntered = (JOptionPane.showInputDialog("Please enter password AGAIN"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement