Guest User

Untitled

a guest
Jul 12th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. import java.io.IOException;
  2. import java.util.Scanner;
  3.  
  4. public class SLAccount2Test {
  5.  
  6. public static void main(String[] args) throws IOException {
  7. Scanner key = new Scanner(System.in);
  8. int regLogin;
  9. do {
  10. System.out.println("What would you like to do? Type 1 to register or 2"
  11. + " to login.");
  12. regLogin = key.nextInt();
  13.  
  14. if (regLogin == 1) {
  15. registerUser(key);
  16. }
  17. if (regLogin == 2) {
  18. login(key);
  19. }
  20. } while (regLogin > 2);
  21. }
  22.  
  23. public static void login(Scanner key) throws IOException {
  24. String username;
  25. String password;
  26.  
  27. System.out.println("Enter username: ");
  28. username = key.nextLine();
  29. System.out.println("Enter password: ");
  30. password = key.nextLine();
  31.  
  32. if (SecondLifeAccount2.existingAccount(username, password) == true) {
  33. System.out.println("Welcome back!");
  34. if (!SecondLifeAccount2.existingAccount(username, password)) {
  35. System.out.println("Username and password don't exist.");
  36. }
  37. }
  38. }
  39.  
  40. public static void registerUser(Scanner key) throws IOException {
  41. String username = "";
  42. String password = "";
  43. System.out.println("Enter username(10-20 characters): ");
  44. boolean isValid = true;
  45. do {
  46. if (!isValid) {
  47. System.out.println("Username invalid or already exists."
  48. + " Re-enter:");
  49. }
  50. username = key.nextLine();
  51. isValid = SecondLifeAccount2.goodUsername(username)
  52. && SecondLifeAccount2.existingUsername(username);
  53. } while (!isValid);
  54. System.out.println("Username accepted.");
  55.  
  56. System.out.println("Enter password(6-16 characters, 1 uppercase"
  57. + ", 1 lowercase, 1 digit): ");
  58. do {
  59. if (!isValid) {
  60. System.out.println("Password invalid. Re-enter:");
  61. }
  62. password = key.nextLine();
  63. isValid = SecondLifeAccount2.goodPassword(password);
  64. } while (!isValid);
  65. System.out.println("Password accepted.");
  66.  
  67. System.out.println("Enter secret question: ");
  68. String secretQuestion = key.nextLine();
  69. System.out.println("Enter secret answer: ");
  70. String secretAnswer = key.nextLine();
  71. System.out.println("Enter date of birth: ");
  72. int dob;
  73. do {
  74. if (!isValid) {
  75. System.out.println("Date of birth invalid. Re-enter:");
  76. }
  77. dob = key.nextInt();
  78. isValid = SecondLifeAccount2.goodDob(dob);
  79. } while (!isValid);
  80. System.out.println("Date of birth accepted.");
  81.  
  82. SecondLifeAccount2 user1 = new SecondLifeAccount2(username,
  83. password, dob, secretQuestion, secretAnswer);
  84.  
  85. System.out.println("Account created!");
  86. System.out.println("Username: " + user1.getUsername());
  87. System.out.println("Password: " + user1.getPassword());
  88. System.out.println("Date of birth: " + user1.getDob());
  89. System.out.println("Secret question: "
  90. + user1.getSecretQuestion());
  91. System.out.println("Secret answer: " + user1.getSecretAnswer());
  92. SecondLifeAccount2.saveToFile(user1);
  93. }
  94. }
Add Comment
Please, Sign In to add comment