Если заявления и имена пользователей/пароли ⇐ JAVA
Если заявления и имена пользователей/пароли
I want my program to prompt user to enter the set user name and password. If the credentials don't match, I want it to loop until either they get it right or they exceed number of attempts.
For example, if they get "username" wrong, program should keep on asking user of "username" until they get the username right or they reach 5 attempts
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"); } } }
Источник: https://stackoverflow.com/questions/363 ... s-password
I want my program to prompt user to enter the set user name and password. If the credentials don't match, I want it to loop until either they get it right or they exceed number of attempts.
For example, if they get "username" wrong, program should keep on asking user of "username" until they get the username right or they reach 5 attempts
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"); } } }
Источник: https://stackoverflow.com/questions/363 ... s-password
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как получить имена пользователей других пользователей в Parse на Android?
Гость » » в форуме Android - 0 Ответы
- 131 Просмотры
-
Последнее сообщение Гость
-
-
-
Как получить имена пользователей других пользователей в Parse в Android?
Anonymous » » в форуме JAVA - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-