Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class Password_DiljotJ_R1 {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. int attempt = 0;
  8.  
  9. String username = "john";
  10. String password = "123";
  11. String usernameEntered;
  12. String passwordEntered;
  13.  
  14. usernameEntered = (JOptionPane.showInputDialog("Please enter the username"));
  15. passwordEntered = (JOptionPane.showInputDialog("Please enter the password"));
  16.  
  17. if (usernameEntered.equals(username) && passwordEntered.equals(password) ){
  18.  
  19. JOptionPane.showMessageDialog(null,"Credentials Match. Welcome John!");
  20. }
  21.  
  22.  
  23.  
  24. else if (usernameEntered.equals(username)) {
  25.  
  26. JOptionPane.showMessageDialog(null,"Password Invalid.");
  27. attempt++;
  28. passwordEntered = (JOptionPane.showInputDialog("Please enter the password AGAIN"));
  29.  
  30. }
  31.  
  32. else if (passwordEntered.equals(password)) {
  33.  
  34. JOptionPane.showMessageDialog(null, "Username Invalid.");
  35. attempt++;
  36. usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
  37. }
  38.  
  39. else {
  40.  
  41. JOptionPane.showMessageDialog(null,"Both username and password are inncorrect. Who are you");
  42. attempt++;
  43. usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
  44. passwordEntered = (JOptionPane.showInputDialog("Please enter password AGAIN"));
  45. }
  46.  
  47. if (attempt == 5){
  48.  
  49. JOptionPane.showMessageDialog(null,"You've reached maximum attempts. Program will now close");
  50. }
  51.  
  52.  
  53. }
  54.  
  55.  
  56. }
  57.  
  58. int attempt = 0;
  59.  
  60. String username = "john";
  61. String password = "123";
  62. String usernameEntered;
  63. String passwordEntered;
  64.  
  65. usernameEntered = (JOptionPane.showInputDialog("Please enter the username"));
  66. passwordEntered = (JOptionPane.showInputDialog("Please enter the password"));
  67.  
  68. if (usernameEntered.equals(username) && passwordEntered.equals(password) ){
  69.  
  70. JOptionPane.showMessageDialog(null,"Credentials Match. Welcome John!");
  71. }
  72.  
  73. if (attempt == 5){
  74.  
  75. JOptionPane.showMessageDialog(null,"You've reached maximum attempts. Program will now close");
  76. break;
  77. }
  78.  
  79. else if (usernameEntered.equals(username)) {
  80.  
  81. JOptionPane.showMessageDialog(null,"Password Invalid.");
  82. attempt++;
  83. passwordEntered = (JOptionPane.showInputDialog("Please enter the password AGAIN"));
  84.  
  85. }
  86.  
  87. else if (passwordEntered.equals(password)) {
  88.  
  89. JOptionPane.showMessageDialog(null, "Username Invalid.");
  90. attempt++;
  91. usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
  92. }
  93.  
  94. else {
  95.  
  96. JOptionPane.showMessageDialog(null,"Both username and password are inncorrect. Who are you");
  97. attempt++;
  98. usernameEntered = (JOptionPane.showInputDialog("Please enter username AGAIN"));
  99. passwordEntered = (JOptionPane.showInputDialog("Please enter password AGAIN"));
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement