Account.java

package mirante.api.account;

import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import mirante.api.security.SecUtils;

@Entity
public class Account {

  @Id
  private String registration;
  private String name;
  private String email;
  private String password;
  private String token;
  private Boolean verified;

  public Account(
      String registration,
      String name,
      String email,
      String password
  ) {
    this.registration = registration;
    this.name = name;
    this.email = email;
    this.password = SecUtils.encoder.encode(password);
    this.verified = false;
  }

  Account() {}

  public Boolean checkPassword(String password) {
    return SecUtils.encoder.matches(password, this.password);
  }

  public void changePassword(String old_password, String new_password) {
    if (SecUtils.encoder.matches(old_password, this.password)) {
      this.password = SecUtils.encoder.encode(new_password);
    }
  }

  public String getRegistration() { return registration; }
  public void setRegistration(String registration) { this.registration = registration; }
  public String getName() { return name; }
  public void setName(String name) { this.name = name; }
  public String getEmail() { return email; }
  public void setEmail(String email) { this.email = email; }
  String getToken() { return token; }
  void setToken(String token) { this.token = token; }

}