简体   繁体   English

如何注销更改用户密码后创建的所有会话?

[英]How to logout all sessions created after user password change?

I store my session id Redis, my session id is global unique, every time login will generate a new session id, so even same user will still have different session id. 我存储我的会话ID Redis,我的会话ID是全局唯一的,每次登录时都会生成一个新的会话ID,因此即使是同一用户,也仍然会有不同的会话ID。 So I have no way to destroy the user's session because I have no way to locate it. 因此,我无法破坏用户的会话,因为我无法找到它。 So how can I design, so as to satisfy my need? 那么如何设计才能满足我的需求?

Sessions are a security issue. 会话是一个安全问题。 I suggest using a library/framework to do it. 我建议使用库/框架来做到这一点。 If you hand roll your own solution and you do it wrong, you open your users up to session hijacking , prediction , and/or fixation . 如果您动手使用自己的解决方案而做错了,则会向用户开放会话劫持预测和/或修复 Those are bad. 那些不好。

If you're using a session library and it's impossible to do what you want without seriously monkeying around, there's probably a reason. 如果您使用的是会话库,并且在没有认真摸索的情况下不可能做自己想做的事情,那可能是有原因的。

If you really want to roll your own rather than using a session library, start here . 如果您真的想自己滚动而不是使用会话库,请从此处开始。

You can: 您可以:

  • set a timestamp createdAt on each session creation 在每次会话创建时设置时间戳createdAt
  • set a timestamp sessionExpire in your user table 在用户表中设置一个timestamp sessionExpire
  • update user.sessionExpire in your resetPassword method resetPassword方法中更新user.sessionExpire
  • on each logged request (so on each refresh or other page browsing, if user session is set), check the user.sessionExpire of the logged user and then compare it with the current session.createdAt 每个登录请求(等各个刷新或其他页面浏览,如果用户会话设置),检查user.sessionExpire登录用户,然后将其与当前比较session.createdAt
  • if session.createdAt < user.sessionExpire then logout 如果session.createdAt < user.sessionExpire然后注销

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

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