I am struggling to figure out how I should override equals and get hashcode for a class I am writing using NHibernate.
Basic business scenario is that users cannot re-use the same password within a 90 day limit.
So I have a "user" that has many "historical passwords"... the user class was easy as I just use the login in the equals. Below is my HistoricalPassword class.
public class HistoricalPassword
{
public virtual int HistoricalPasswordId { get; set; }
public virtual User User { get; set; }
public virtual DateTime ChangeDate { get; set; }
public virtual string FormerPassword { get; set; }
}
I would say from a business sense that the combination of the User and the ChangeDate would give me equality. However... it does not seem correct to reference the user in the equals method (since for one thing that would cause a lazy load to happen)... and also from what I read using the PK of HistoricalPasswordId is a no-no as well.
Can anyone provide some advice on how they would override equals for this?
EDIT ::: I think I might have been a little misleading on the way I asked the question. I'm not confused on how to enforce the business rule of making sure the passwords are not reused... nor on how I know if two passwords are equal or are secure. What I really want to know is at the entity level specifically relating to NHibernate how would I override Equals for this object so that NHibenate does not end up with dupes in the session and/or cache. According to the NHibernate doc (https://www.hibernate.org/hib_docs/nhibernate/html/persistent-classes.html) I should override equals using Business key equality. In this case I'm just not sure if using the referenced object of User in the compare is a good idea.