PHP的Cookie保持用户登录 - 这是足够安全? [英] PHP Cookie to keep user logged in - is this secure enough?

查看:317
本文介绍了PHP的Cookie保持用户登录 - 这是足够安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储加密密码的用户数据库,想创造一个保存我登录的饼干。我相信下面的方法应该是安全的足够我的目的,但我想听听你的想法:

I have a user database that stores encrypted passwords, and would like to create a "Keep me logged in" cookie. I believe the following method should be secure enough for my purposes, but I would like to hear your thoughts:


  1. 如果用户选择记住我的登录框,并提供了正确的凭据,创建一个包含一个非常大的随机字符串的cookie(称之为的航标的)。这也被存储在用户表中的一个单独的列。

  2. 用户每次访问页面,搜索用户表中的航标的饼干。如果它不存在,什么也不做。如果它确实存在,检索用户的信息,并把它们作为登录

  3. 当用户注销,或原木在没有选中此复选框,破坏的航标的饼干。

  1. If the user selects the "Keep me logged in box" and provides proper credentials, create a cookie that contains a very large random string (call this the beacon). This is also stored in a separate column in the user table.
  2. Each time a user visits the page, search the user table for the beacon cookie. If it doesn't exist, do nothing. If it does exist, retrieve the user's information and treat them as logged in.
  3. When the user logs out, or logs in without the box checked, destroy the beacon cookie.

如果有人要正确地猜出信标串这可以被操纵,但我的意图是使大,足够随机,这是很难做到的。

This could be manipulated if someone were to properly guess the beacon string, but my intent is to make it large and random enough that this is very difficult to do.

推荐答案

我presume这是除了正常的会话处理后作为重建会议的方式正在做。

I presume this is being done in addition to normal session handling as way of recreating the session later.

有可以做,以提高安全性的几件事情。

There are a few things that can be done to improve security.


  1. 使用SSL,使拦截cookie的要困难得多。

  2. 重生每次使用后Cookie哈希值。它应该只对于一次登录有效。

  3. 如果您存储以此为1 cookie来1用户,它不会如果用户在多个设备上工作(从第1设备Cookie由饼干上的第二个设备覆盖)。

  4. 哈希需要是随机的,在一代应该没有纳入任何用户数据。

  5. 的用户数据(电子邮件,尤其是密码)应需要密码才能改变。如果cookie被拦截,拦截器将无法更改帐户数据。

这篇关于PHP的Cookie保持用户登录 - 这是足够安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆