Class User
java.lang.Object
ai.tutor.cab302exceptionalhandlers.model.User
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getId()
static String
hashPassword
(String passwordPlaintext) Hashes a plaintext password using the Scrypt algorithm.void
setId
(int id) void
setPasswordHash
(String passwordHash) void
setUsername
(String username) boolean
verifyPassword
(String passwordPlaintext) Verifies whether the plaintext password matches the stored password hash.
-
Constructor Details
-
User
Constructs a User object.- Parameters:
username
- The username of the user, must be 1-25 alphanumeric characterspasswordHash
- The hashed password of the user, must not be null or empty- Throws:
IllegalArgumentException
- if any of the parameters are invalid- See Also:
-
-
Method Details
-
getId
public int getId() -
setId
- Throws:
IllegalArgumentException
-
getUsername
-
setUsername
- Throws:
IllegalArgumentException
-
getPasswordHash
-
setPasswordHash
- Throws:
IllegalArgumentException
-
verifyPassword
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 thepasswordPlaintext
isnull
or empty
-
hashPassword
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 thepasswordPlaintext
isnull
or empty
-