问题描述
我有一个使用Identity的ASP.NET项目.对于有关密码的身份配置,正在使用PasswordValidator
.如何将密码的实施范围扩展到PasswordValidator
当前的范围(RequiredLength
,RequiredDigit
等)之外,以满足N天后要求密码过期的要求?
I have a ASP.NET project using Identity. For Identity Configuration regarding passwords, the PasswordValidator
is being used. How do I expand the enforcement of password beyond what PasswordValidator
has currently (RequiredLength
, RequiredDigit
, etc.) to satisfy a requirement that asks for password expiration after N days?
推荐答案
ASP.NET Identity 2中没有内置此类功能.最简单的方法是在用户上添加 LastPasswordChangedDate 之类的字段.然后在每次授权期间检查此字段.
There is no such functionality builtin ASP.NET Identity 2. Easiest is to add a field on the user like LastPasswordChangedDate. And then check this field during each Authorization.
public class ApplicationOAuthProvider : OAuthAuthorizationServerProvider
{
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
var user = await GetUser(context.UserName, context.Password);
if(user.LastPasswordChangedDate.AddDays(20) < DateTime.Now)
// user needs to change password
}
}
这篇关于如何使用ASP.NET Identity Framework设置密码过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!