Advertisement
Guest User

Untitled

a guest
May 11th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. package com.gnarly;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. private static final Scanner scanner = new Scanner(System.in);
  8.  
  9. private static final String USERNAME = "Gnarly";
  10. private static final String PASSWORD = "123";
  11.  
  12. private String username;
  13. private String password;
  14.  
  15. public static void main(String[] args) {
  16. new Main();
  17. }
  18.  
  19. public Main() {
  20. askForUsername();
  21. askForPassword();
  22. welcomeUser();
  23. }
  24.  
  25. private void askForUsername() {
  26. do {
  27. System.out.print("Type your username : ");
  28. username = scanner.nextLine();
  29. if (!username.equalsIgnoreCase(USERNAME)) {
  30. System.out.println("You have entered an invalid username. Try again.");
  31. }
  32. } while (!username.equalsIgnoreCase(USERNAME));
  33. }
  34.  
  35. private void askForPassword() {
  36. do {
  37. System.out.print("Type your password : ");
  38. password = scanner.nextLine();
  39. if (!password.equalsIgnoreCase(PASSWORD)) {
  40. System.out.println("You have entered an invalid password. Try again.");
  41. }
  42. } while (!password.equalsIgnoreCase(PASSWORD));
  43. }
  44.  
  45. private void welcomeUser() {
  46. System.out.println("Hello, " + username);
  47. System.out.println("Type .changepassword to change your password.");
  48. String command = scanner.nextLine();
  49. if (command.equalsIgnoreCase(".changepassword")) {
  50. do {
  51. System.out.println("Please type in your new password : ");
  52. String newPassword = scanner.nextLine();
  53. System.out.println("Please retype your new password : ");
  54. String newPasswordVerify = scanner.nextLine();
  55. if (newPassword.equalsIgnoreCase(newPasswordVerify)) {
  56. password = newPassword;
  57. System.out.println("Your new password has been set.");
  58. } else {
  59. System.out.println("The two passwords you entered didn't match. Try again.");
  60. }
  61. } while (password.equalsIgnoreCase(PASSWORD));
  62. }
  63. }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement