PHP “Remember Me” security flaw?

后端 未结 4 1753
半阙折子戏
半阙折子戏 2021-02-13 18:15

I\'m in the middle of coding a \'remember me\'-equipped login form, and so far the tutorials I\'ve read (partly to make sure I\'m doing it right) all say to store the encrypted

4条回答
  •  庸人自扰
    2021-02-13 18:57

    Never save passwords in any way (encrypted password which can be used to login is still a password) on client.

    Use randomly generated key, safely stored on server. These keys can be revoked later unlike the encrypted passwords which will be valid until changed.

    Using php you can generate random key like this md5(uniqid(mt_rand(), true)). For better safety store it salted and hashed in db.

    Example table:

    login_keys (
      user_id int,
      key char(40), # sha1
      salt char(15)
    )
    

    Also note you should enable the HTTP only cookie option.

提交回复
热议问题