Skip to content

Commit

Permalink
Added password hashing to User
Browse files Browse the repository at this point in the history
  • Loading branch information
robinsp committed Mar 3, 2026
1 parent eed6f98 commit 9b9d8ea
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.UUID;

// TODO: Passord må hashes!!!
// TODO: Unntakshåndtering mangler
// TODO: Enhetstesting mangler

Expand All @@ -12,10 +11,12 @@
* @author Robin Strand Prestmo
*/
public class User {
private static final PasswordHasher passwordHasher = new PasswordHasher();

private final UUID id;
private String name;
private String email;
private String password;
private String passwordHash;
private final String role;
private final Settings settings;
private final Inbox inbox;
Expand Down Expand Up @@ -43,7 +44,7 @@ public User(UUID id,
this.id = id;
this.name = name;
this.email = email;
this.password = password;
this.passwordHash = passwordHasher.getHashPassword(password);
this.role = role;
this.settings = settings;
this.inbox = inbox;
Expand Down Expand Up @@ -77,16 +78,21 @@ public Inbox getInbox() {

// Add Setters


public void setName(String name) {
this.name = name;
}

public void setPassword(String password) {
this.password = password;
this.passwordHash = passwordHasher.getHashPassword(password);
}

public void setEmail(String email) {
this.email = email;
}
}

// Other methods

public boolean checkPassword(String password) {
return passwordHasher.isValidPassword(password, passwordHash);
}
}

0 comments on commit 9b9d8ea

Please sign in to comment.