我正在寻找一种最新的方法来让用户登录着名的“记住我”#39;复选框。
这是我迄今为止结合其他帖子和教程所得到的:
用户输入用户名和密码。如果有效 - 生成包含标识符和标记的Cookie。这两个值都是不可取的随机数/字符。
标识符和令牌存储在用户ID 的数据库中。
当未登录的用户使用登录Cookie访问网站时,会在数据库中查找标识符;如果存在,则比较令牌;如果没有,Cookie将被忽略,用户必须使用他/她的密码登录。
如果标记匹配 - 用户已通过身份验证:
我错过了什么吗?
答案 0 :(得分:0)
您已经关闭了机制,以便根据用户登录状态将cookie存储到数据库。我仍然会做一个清单,以确保它是安全的:
限制存储在Cookie中的敏感信息量。
** this is ok, you're only storing Identifier and Token information
<强> Limit the subdomains and paths to prevent interception by another application.
强>
强制执行SSL,以便不以明文形式发送Cookie。
** 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无法访问。
您可以通过查看之前的stackoverflow帖子来实现:How do you set up use HttpOnly cookies in PHP