密码更改时使用户凭据无效
Invalidate user credentials when password changes
我有一个 Asp.net MVC 网站。当用户更改密码时,是否所有浏览器的登录都会失效?我的意思是用户是否需要使用新密码登录所有浏览器?如果没有,有没有办法做到这一点?
不会立即,默认情况下,旧 cookie 在 asp.net 身份 2 中失效需要 30 分钟,asp.net 身份不会针对每个请求检查数据库,它有一个interval,用SecurityStamp
改,可以设置成Startup.Auth.cs
,默认30分钟,设置validateInterval
为0,这不是最有效的方法,因为每次请求将访问数据库以检查 cookie 是否仍然有效,但如果您想立即查看效果,它会完成工作,另请查看 this and this.
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))
}
});
我有一个 Asp.net MVC 网站。当用户更改密码时,是否所有浏览器的登录都会失效?我的意思是用户是否需要使用新密码登录所有浏览器?如果没有,有没有办法做到这一点?
不会立即,默认情况下,旧 cookie 在 asp.net 身份 2 中失效需要 30 分钟,asp.net 身份不会针对每个请求检查数据库,它有一个interval,用SecurityStamp
改,可以设置成Startup.Auth.cs
,默认30分钟,设置validateInterval
为0,这不是最有效的方法,因为每次请求将访问数据库以检查 cookie 是否仍然有效,但如果您想立即查看效果,它会完成工作,另请查看 this and this.
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))
}
});