Skip to content

Commit

Permalink
feat[User]: Add Bcrpyt in verifying password in class and dependency …
Browse files Browse the repository at this point in the history
…in pom.xml
  • Loading branch information
Fredrik Marjoni committed Feb 26, 2026
1 parent 837cf93 commit b9693b7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-crypto -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
<version>7.0.2</version>
</dependency>
</dependencies>

<build>
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/edu/group5/app/model/user/User.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package edu.group5.app.model.user;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
/**
* User class represents a user in the system. It is an abstract class that will be extended by specific user types such as Donor, Recipient, and Admin.
* Each user has a unique userId, a role that defines their permissions in the system, and personal information such as first name, last name, email, and password hash.
* The constructor validates that all required fields are provided and throws an IllegalArgumentException if any of the fields are null or empty.
* This ensures that the User objects are always in a valid state when created.
* The class also includes a method to verify the user's password
* by comparing the provided plaintext password with the stored hashed password using BCrypt.
*
*/
public abstract class User {
private int userId;
Expand All @@ -21,7 +25,7 @@ public abstract class User {
* @param firstName the first name of the user
* @param lastName the last name of the user
* @param email the email address of the user
* @param passwordHash the hashed password of the user
* @param passwordHash the hashed password of the user, used for authentication purposes
*/
public User(int userId, String role, String firstName,
String lastName, String email, String passwordHash) {
Expand Down Expand Up @@ -101,14 +105,16 @@ public String getPasswordHash() {
}

/**
* Verifies if the provided password matches the stored password hash for the user.
* This method should implement the logic to hash the input password
* and compare it with the stored password hash.
* Verifies if the provided password matches the stored password hash.
* This method uses BCrypt to compare the plaintext password with the hashed password.
* @param password the plaintext password to verify
* @return true if the password is correct, false otherwise
*/
public boolean verifyPassword(String password) {
// TODO Implement password verification logic here, e.g., using a hashing algorithm
return true; // Placeholder return value
if (password == null || password.isEmpty()) {
return false;
}
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
return encoder.matches(password, this.passwordHash);
}
}
Binary file modified target/classes/edu/group5/app/model/user/User.class
Binary file not shown.

0 comments on commit b9693b7

Please sign in to comment.