如何使用ASP.NET Identity Framework设置密码过期 [英] How to setup password expiration using ASP.NET Identity Framework

查看:238
本文介绍了如何使用ASP.NET Identity Framework设置密码过期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Identity的ASP.NET项目.对于有关密码的身份配置,正在使用PasswordValidator.如何将密码的实施范围扩展到PasswordValidator当前的范围(RequiredLengthRequiredDigit等)之外,以满足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设置密码过期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆