Advertisement
Guest User

Untitled

a guest
Oct 15th, 2018
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Project {
  4.  
  5. public static void main(String[] args) {
  6. // TODO Auto-generated method stub
  7. String[][] names= new String[2][5];
  8. String userName, password;
  9. boolean checkPoint=false;
  10. Scanner myScanner= new Scanner(System.in);
  11. //Usernames
  12. names[0][0]= "Username1";
  13. names[0][1]= "Username2";
  14. names[0][2]= "Username3";
  15. names[0][3]= "Username4";
  16. names[0][4]= "Username5";
  17.  
  18. //Passwords
  19. names[1][0]= "Password1";
  20. names[1][1]= "Password2";
  21. names[1][2]= "Password3";
  22. names[1][3]= "Password4";
  23. names[1][4]= "Password5";
  24.  
  25. //Prompt User for Username/See if Username exists.
  26. System.out.println("What is the Username?");
  27. userName=myScanner.nextLine();
  28.  
  29. for(int y=0; y<5; y++)
  30. {
  31. if(userName.equals(names[0][y]))
  32. {
  33. break;
  34. }
  35. else
  36. if(y==4) {
  37. System.out.println("Username does not exist.");
  38. System.exit(0);
  39. }
  40. }
  41.  
  42. //Prompt User for Password, and check password.
  43. System.out.println("What is the Password");
  44. password=myScanner.nextLine();
  45.  
  46. for(int i=0; i<5; i++)
  47. for(int k=0; k<2; k++)
  48. if(userName.equals(names[0][i]))
  49. {
  50. if(password.equals(names[k][i]))
  51. checkPoint=true;
  52. }
  53.  
  54. //Check to see if credentials are correct
  55.  
  56. if(checkPoint) {
  57. System.out.println("Login Successful");
  58. }
  59. else {
  60. System.out.println("Wrong Password!");
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement