我创建了一个名为
这是我的代码:
感谢您的帮助。
PasswordHistory
的表。每当用户更改密码时,当前密码应被复制到PasswordHistory表中。策略是以下两者中最严格的之一:
- 用户不能使用最近8个密码中的任何一个
- 或者过去2年内使用过的密码
这是我的代码:
var _limitDate = DateTime.Now.AddYears(-2);
int n = db.PasswordsHistory.Where(pwd => pwd.UserId == userId && pwd.ChangeDate > _limitDate).Count();
var pwdList = new List<PasswordHistory>();
if(n >= 8)
{
pwdList = db.PasswordsHistory
.Where(pwd => pwd.ChangeDate > _limitDate)
.ToList();
}
else
{
pwdList = db.PasswordsHistory
.OrderByDescending(pwd => pwd.ChangeDate)
.Take(8)
.ToList();
}
if (pwdList.Count == 0)
{
return false;
}
else
{
foreach (var pwd in pwdList)
{
//compare the password entered by the user with the password stored in the PasswordHistory table
}
}
感谢您的帮助。