Remember me Cookie best practice?

前端 未结 7 1624
感动是毒
感动是毒 2020-12-01 05:30

I read about many old questions about this argument, and I thought that the best practice is to set up a cookie with username,user_id and a random

7条回答
  •  鱼传尺愫
    2020-12-01 06:22

    I wouldn't even store the username in a cookie, just a random token generated with a near impossible to crack technique and map that to the user in your database, and never store user's password even hashed in a cookie, it will be open to Brute Force Attack. Yes if someone steal the token he can access user's account but the password will not be compromised and the token will be invalidated as soon as the real user logs out. Also remember that you shouldn't allow sensitive tasks like changing password to a user who just have a valid token, you need to ask for the password again for such tasks.

提交回复
热议问题