Web authentication state - Session vs Cookie?

后端 未结 5 1430
鱼传尺愫
鱼传尺愫 2020-12-02 17:09

What\'s the best way to authenticate and track user authentication state from page to page? Some say session state, some say cookies?

Could I just use a session var

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 17:53

    There's no perfect way to do it. If you store it in a cookie you'll take flak that cookies can be stolen. If you store it in the session you'll take flak because sessions can be hijacked.

    Personally, I tend to think a session is a little more reliable because the only thing stored on the client is a session key. The actual data remains on the server. It plays the cards a little closer to the chest, if you will. However, that's just my preference, and a good hacker would be able to get past shoddy security regardless.

    No matter what you do, don't try to implement this yourself. You'll get it wrong. Use the authentication system provided by your specific platform. You also need to make sure you have adequate security precautions protecting the authentication token.

提交回复
热议问题