php - 公司采用前后端分离, token我直接用sessionid可以么?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 12:58:06
0
7
981

我们公司准备用前后端分离做项目, 前后端为了保持登录状态, 我看了网上很多都说的用token来保持登录, 现在我在token中直接存放md5(sessionid)可以么?有没有什么问题?

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(7)
左手右手慢动作

Essentially, the front-end encrypts the data to reduce the readability, such as the user's sensitive data, for the purpose of privacy protection. If you pass the seesion_id, there is no need to encrypt it. As for the md5 method mentioned above, it is wrong (for passing seesion_id), because the seesion_id itself is used as a key, and md5 is a hash method (irreversible). If the backend wants to use it, it can be used directly. Come and use it, your layers of md5 are meaningless (if it is hijacked, just use it directly)

The token issue you mentioned lies in how the backend implements the authentication part, whether to restore the session to store information, or to use the token to verify the interface calling authority. It varies depending on how the backend is implemented.

Session is saved by a cookie placed in the browser, and relies on the browser's cookie expiration time to control the login retention time (client perspective).

For the rest of the content, please refer to this session cookie vs token

为情所困

Encrypt a few more layers, an md5 is too simple.

習慣沉默

Token, just have the MD5 encrypted date when logging in, then throw it into redis, and then block it in the interceptor to make a judgment

Ty80

As long as no sensitive content (passwords, etc.) is stored, there is no problem for me. It is recommended to use the popular jwt. There are libraries implemented in various languages, and it is very convenient to use.

黄舟

Session id is just a token, and md5 is redundant.

世界只因有你

sessionid Isn’t it an encrypted plaintext token? There is no need to md5 it

给我你的怀抱

It’s absolutely fine, use jwt. Pay attention to verifying the legality of the token.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template