douhuan6065 2014-05-26 22:17
浏览 29

如何建立防弹cookie系统?

I know the big posts about the cookie topic but I still have some unclear questions about the realization. My thoughts were these:

In my database I save for each of my user a cookie_token which is generated randomly when the account gets created. Just a random SHA1 or maybe a changed HASH of his BCRYPT.

Then my login logic would be:

If a user visits a private site

  1. Is the Session LoggedIn true?
    1. Yes: All ok, stop further checks
    2. No: continue with 2.
  2. Query the DB if the user with his ID has the same token as saved in his cookie.
    1. If Yes set the LoggedIn cookie
    2. Redirect.

But I've also read of a so called series_identifier but I couldn't figure out what this exactly is. As I understood it somehow should change every time the user creates a new session or something like this, but I'm not sure how to implement this. Can anyone give me a suggestion how to do that, or maybe an other approach to improve the security of the cookie / login process?

Best regards, Michael

  • 写回答

1条回答 默认 最新

  • duanhao8540 2017-12-28 19:58
    关注

    If you're looking to build tamper-resistant cookies for long-term authentication, this is a good introduction, and this formalizes the strategy a bit further.

    What you're doing is storing half the token as a selector (used in SELECT queries) and a hash of the other half of the token in the database.

    To validate, you split the token in half, use the first to find the correct database record, then re-hash the second half and compare the one you just calculated with the one stored (using hash_equals()). If they match, great.

    If you want to go a step further, you could also encrypt your cookies using authenticated encryption, but that's probably overkill.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。