首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >登录“记住我”Cookie -最佳安全实践

登录“记住我”Cookie -最佳安全实践
EN

Stack Overflow用户
提问于 2014-12-22 16:17:03
回答 1查看 675关注 0票数 1

我正在寻找一个最新的方法,让一个用户登录与著名的‘记住我’复选框。

到目前为止,我还没有把其他文章和教程结合起来:

  • 用户输入用户名和密码。如果有效,将生成包含标识符令牌的Cookie。这两个值都是不可猜测的随机数/字符。
  • 标识符令牌存储在具有用户id的数据库中。
  • 当非登录用户使用登录Cookie访问网站时,将在数据库中查找标识符;如果存在,则对令牌进行比较;如果没有,则忽略Cookie,用户必须使用其密码登录。
  • 如果标记与匹配,则对用户进行身份验证:

代码语言:javascript
复制
- The Cookie is destroyed.
- A new Cookie is issued with a different **Identifier** and **Token**.
- The Database is **updated** with the new **Identifier** and **Token** values against the **user id**.

我错过了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-22 16:30:07

您已经关闭了机制,以便根据用户登录状态将cookie存储到db。我仍然会做一个检查表,以确保它是安全的:

限制存储在cookie.中的敏感信息的数量。

代码语言:javascript
复制
** this is ok, you're only storing Identifier and Token information

Limit the subdomains and paths to prevent interception by another application.

强制使用SSL,这样cookie就不会以明文形式发送。

代码语言:javascript
复制
** if you don't already have ssl, which is a good idea to have, you can enable ssl to send that information encrypted (you have to do that in your web server config). you can issue yourself (self-signed) ssl certificate, it won't be insured but at least the information would go in or transfer as encrypted.  

使cookie HttpOnly无法被javascript.访问。

您可以通过查看以前的堆栈溢出帖子:How do you set up use HttpOnly cookies in PHP来实现

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27606382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档