Tworzę system logowania do mojej aplikacji i przeczytałem gdzieś że haseł nie powinno przechowywać się w bazie danych. Dodałem więc adnotację @transient i hasło się nie zapisuje. Problem polega na tym że teraz pisząc logikę logowania nie za bardzo wiem skąd to hasło wziąć aby zweryfikować użytkownika. Zastanawiam się czy szyfrowanie hasła przy zapisie nie byłoby wystarczające. Czy mógłby mi ktoś przybliżyć temat i wytłumaczyć jak to właściwie powinno wyglądać albo podesłać materiały poruszające ten temat?
@Entity
@Table(name = "customers")
public class Customer implements VerificableUser {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_customer")
private Integer id;
@Column(nullable = false, unique = true)
@NotEmpty(message = "please provide login")
private String login;
@Column(nullable = false)
@NotEmpty()
private String role;
@Column(nullable = false)
@NotEmpty(message = "please provide first name")
private String firstName;
@Column(nullable = false)
@NotEmpty(message = "please provide last name")
private String lastName;
@Transient
private String password;
@Column(nullable = false, unique = true)
@Email(message = "please provide valid email")
private String email;
public Customer() {
this.role = "Customer";
}
//gettery i settery
}
@Service
public class CustomerService {
CustomerRepo customerRepo;
@Autowired
CustomerService(CustomerRepo customerRepo){
this.customerRepo = customerRepo;
}
public void saveCustomer(Customer customer){
customerRepo.save(customer);
}
public Customer getCustomer(String login){
return customerRepo.findByLogin(login);
}
public boolean verifyCustomer(String login, String password) {
VerificableUser verificableUser = customerRepo.findByLogin(login);
if(verificableUser.getPassword() == password) return true;
else return false;
}
}