简体   繁体   English

当用户在ASP.NET/ASP.NET MVC中更改密码时,如何使任何自动登录cookie到期?

[英]How to expire any auto-login cookie when user change password in ASP.NET/ASP.NET MVC?

I use ASP.NET Form Authentication method in my project to keep login information as user id in user's cookie like the below code. 我在项目中使用ASP.NET表单身份验证方法,将登录信息作为用户ID保留在用户的Cookie中,如以下代码所示。 It works well without any problem. 它运作良好,没有任何问题。

FormsAuthentication.SetAuthCookie(userInfo.id.ToString(), model.AutoLogin);

But the problem occurs when user use automatic login and then he change his password. 但是,当用户使用自动登录然后更改密码时,就会出现问题。 In some site, I see it will force you to re-login when you change password. 在某些站点上,我看到它会迫使您在更改密码时重新登录。 It's quite easy for forcing current page to log out and re-login again. 强制当前页面注销并重新登录非常容易。

But I don't find any nice idea for forcing other auto-login cookie in other browser to login again. 但是我发现在其他浏览器中强制其他自动登录cookie再次登录的好主意。 I have some quite ugly idea for doing that but I don't like it. 我这样做有一个很丑陋的主意,但我不喜欢它。

  1. Keep latest change password date in user data. 在用户数据中保留最新的更改密码日期。
  2. Put it in authentication cookie like the following code. 像下面的代码一样,将其放入身份验证cookie中。

    FormsAuthentication.SetAuthCookie(userInfo.id.ToString() + '|' + userInfo.ChangePasswordDate, model.AutoLogin); FormsAuthentication.SetAuthCookie(userInfo.id.ToString()+'|'+ userInfo.ChangePasswordDate,model.AutoLogin);

Do you have any better idea for solving this question that work with ASP.NET and ASP.NET MVC? 您是否有解决与ASP.NET和ASP.NET MVC一起使用的问题的更好的主意?

Thanks, 谢谢,

The authentication cookie contains only the encrypted username. 身份验证cookie仅包含加密的用户名。 So either you really force the user to re-login by signing him out ( FormsAuthentication.SignOut ) or you do nothing in which case the old cookie is still valid, still authenticated but his password was changed in the datastore so that next time him tries to login he will need to use this new password. 因此,您可以通过注销用户( FormsAuthentication.SignOut )来强制用户重新登录,或者您什么也不做,在这种情况下,旧的cookie仍然有效,仍然经过身份验证,但是密码已在数据存储区中更改,以便下次他尝试要登录,他将需要使用此新密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM