【问题标题】:Invalidate user credentials when password changes密码更改时使用户凭据无效
【发布时间】:2015-06-08 08:26:07
【问题描述】:

我有一个 Asp.net MVC 网站。当用户更改密码时,是否所有浏览器的登录都无效?我的意思是用户是否需要使用新密码登录所有浏览器?如果没有,有没有办法做到这一点?

【问题讨论】:

    标签: asp.net asp.net-mvc security asp.net-identity


    【解决方案1】:

    不是立即的,默认情况下,旧 cookie 在 asp.net 身份 2 中失效需要 30 分钟,asp.net 身份不会在每次请求时检查数据库,它有一个间隔,使用SecurityStamp要更改它,您可以在Startup.Auth.cs 中设置它,默认为 30 分钟,将validateInterval 设置为 0,这不是最有效的方法,因为在每次请求时都会访问数据库以检查 cookie 是否仍然有效,但如果你想立即看到效果,它会起作用,也可以看看thisthis

    app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                // Enables the application to validate the security stamp when the user logs in.
                // This is a security feature which is used when you change a password or add an external login to your account.  
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromSeconds(0),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });
    

    【讨论】:

    • 非常感谢。我觉得30分钟就够了。我只是想知道它是否会使凭证无效。很高兴知道密码更改最终会注销用户(30 分钟后)。
    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 2021-01-18
    • 2019-05-19
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 2021-09-28
    • 1970-01-01
    相关资源
    最近更新 更多