Is it safe to store (hashed) passwords in a cookie?

情到浓时终转凉″ 提交于 2019-12-01 22:38:40

Sessions are usually keyed to IP addresses at some level somewhat preventing session theft.

Beyond that, the session ID doesn't contain any personal information; your password, even salted and hashed does. Passwords, salted and hashed as they may be, can be reused; session ID's can't. Once the session is over, it's over, you need a new session ID to be able to impersonate the user again.

By putting the hashed password + salt in the cookie, you:

  • Open up an unlimited bruteforce vector
  • Allow the cookie to be copied and used by anyone (it always lets access; whereas a session does so for a period of time).
  • Make it harder to change hashing schemes, if it becomes relevant

Further, you generally need to store something else, to identify the user (like their user id, so you can look up their password and match it). This may lead other obscure problems.

So you're best just going with the session id approach.

Among other distinctions, if a session is stored, you own this one session. If a pwd is taken, you own every session of that user from now on.

How about letting someone else deal with and think about all these issues for you? That is, use OpenID, Windows Live ID, Facebook Connect, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!