java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.User

public class User extends Object
Represents a user in the QuizWhiz application.

A user must have a unique username and a password hash. Passwords are hashed and salted using the Scrypt algorithm

Author:
Joshua M.
See Also:
  • Constructor Details

  • Method Details

    • getId

      public int getId()
    • setId

      public void setId(int id) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • getUsername

      public String getUsername()
    • setUsername

      public void setUsername(String username) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • getPasswordHash

      public String getPasswordHash()
    • setPasswordHash

      public void setPasswordHash(String passwordHash) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • verifyPassword

      public boolean verifyPassword(String passwordPlaintext) throws IllegalArgumentException
      Verifies whether the plaintext password matches the stored password hash.

      This method uses the Scrypt algorithm to check if the provided plaintext password matches the hashed password stored in the user object.

      Password.check does not check whether the plaintext password is empty, hence this method manually validates the password before checking.

      Parameters:
      passwordPlaintext - the plaintext password to verify
      Returns:
      true if the password is valid and matches the stored hash, false otherwise
      Throws:
      IllegalArgumentException - if the passwordPlaintext is null or empty
    • hashPassword

      public static String hashPassword(String passwordPlaintext) throws IllegalArgumentException
      Hashes a plaintext password using the Scrypt algorithm.

      Passwords are hashed with a random salt of 16 bytes to enhance security.

      Parameters:
      passwordPlaintext - the plaintext password to hash
      Returns:
      the hashed password as a String
      Throws:
      IllegalArgumentException - if the passwordPlaintext is null or empty