Exemplo n.º 1
0
  // prompt the user to login
  static User login() {
    boolean hasUser = false;
    String username, pass;

    System.out.println("\nLogin Form (input \"back\" to cancel operation)");

    while (!hasUser) {
      System.out.print("Username: "******"Password: "******"back") || pass.equalsIgnoreCase("back")) {
        System.out.println("Cancelling operation, reverting back to user menu.\n");
        return null;
      }

      if (FileManager.userExist(username)) {
        if (FileManager.checkPass(username, pass)) {
          user = FileManager.loadUser(username);
          hasUser = true;
        } else {
          System.out.println("Incorrect Password!");
        }
      } else {
        System.out.println("The username you have specified does not exist!");
      }
      System.out.println(); // formating
    }
    return user;
  }
Exemplo n.º 2
0
  // prompt the user to register
  static User register() {
    boolean regComplete = false;
    String username, password, name;
    int age;

    System.out.println("Please fill in the information below to register a new user.");

    while (!regComplete) {

      System.out.print("Desired Username: "******"Password: "******"Name: ");
        name = in.next();
        System.out.print("Age: ");
        try {
          age = Integer.parseInt(in.next());

          // Create the new user
          user =
              new User(
                  -1, username, password, name,
                  age); // -1 is a temporary ID which will be overwritten
          FileManager.addUser(user);
          if (FileManager.userExist(username)) {
            regComplete = true;
            // Reload the user with correct corresponding ID
            user = FileManager.loadUser(username);
          }

        } catch (NumberFormatException mismatch) {
          System.out.println("You did not input an integer..\nPlease re-enter your information");
        }

      } else {
        System.out.println("The username that you want already exist!\nPlease try another one.");
      }
    }
    return user;
  }