当前位置:网站首页>Token, cookie and session
Token, cookie and session
2022-06-21 08:59:00 【Break through】
token、session and cookie What is it ?
http It's a stateless protocol
What is statelessness ?
That is to say, this request has nothing to do with the last one , Don't know each other , Not related . The advantage of this statelessness is that it is fast .
cookie
cookie There is a way to identify users in the browser , The server signs and issues unused for each user session id Send it to the browser and store it in cookie in , I will bring this with me on my next visit session id, The server will know which user this access is .
cookie Problems faced :
CSRF( Cross-site request forgery ) attack , This is easier to solve , Many frameworks block this issue
Some clients do not support cookie, Manual setting required , Like an applet
The browser to cookie Limited , You can't set it manually cookie, There's a problem with mixed nesting development , For example, small program jump H5 page , Can't carry cookie
Browser for single cookie The saved data cannot exceed 4k, Many browsers restrict a site from being saved 20 individual cookie
session
session( conversation ), It is a way to identify users in the server , The server generates different for each user session id, And the corresponding information , Such as user id And login time, etc .
session Problems faced :
Load balancing with multiple servers , It's not easy to confirm whether the current user is logged in , Because multiple servers don't share session. This problem can also be session Exist in a server to solve , But it can't achieve the effect of load balancing completely
Each client only needs to store its own session id, But the server needs to store all users' information session id, It's also a pressure on the server
Be careful :
cookie Just to achieve session One of the solutions . Although it's the most commonly used , But it's not the only way . Ban cookie There are other ways to store , For example url in
Now it's mostly session+cookie, But only session no need cookie, Or just cookie no need session, In theory, you can keep the conversation state . But in reality, for many reasons , It is not used alone
use session Just keep one on the client side id, In fact, a large amount of data is stored on the server . If you use it all cookie, When the amount of data is large, the client does not have so much space
If only cookie no need session, Then all the account information is saved in the client , Once hijacked , All information will be leaked . And the amount of client data becomes larger , The amount of data transmitted on the network will also increase
token
token Also known as token , from uid+time+sign+【 Fixed parameter 】
uid: The unique identity of the user
time: Timestamp of current time
sign: Signature , Use hash/encrypt Compressed into fixed length hexadecimal string , To prevent malicious splicing by third parties
Fixed parameter ( Optional ): Add some common fixed parameters to token In order to avoid repeated search
token The authentication method of is similar to the temporary integer signature , And it is a server stateless authentication method , Unusual use and REST API Scene .
token In the client, it is generally stored in localStorage,cookie, or sessionStorage in . In the server, it is usually stored in the database
summary
session Storage and server , It can be understood as a list of States , Have a unique identifier sessionId, Usually stored in cookie in . Server received cookie After that, it is concluded that sessionId, Go again session Find... In the list , To find a response session.
cookie Similar to a token , Equipped with sessionId, Store on client , Browsers usually add
token It is also similar to a token , No state , User information is encrypted to token in , Server received token After decryption, you can know which user , It needs to be added manually by the developer
边栏推荐
- 【JUC系列】Executor框架之CompletionService
- nodejs的post请求json类型及表单类型
- The skill of using ADB and the principle of USB communication
- An app developed based on retrotfit2.1+material design+ijkplayer
- Audio immersive experience
- 在使用各种软件时 积累的快捷键
- Talking about Festinger effect
- Shortcut keys accumulated when using various software
- finally block can not complete normally
- 4.6 lodash usage documents
猜你喜欢

Unity 5 自带的Mono也可以支持C# 6

Tsinghua University | van: visual attention network

What should I do if a white page appears during MySQL installation

【VS】【使用问题】【解决方案】VS2010打开一直停留在启动界面

TiDB3.0- 4.0 内存控制/修改日志保存天数/最大索引长度

Using the method of combining shapes in illustrator

解密FTP

Tidb3.0- 4.0 memory control / modification log saving days / maximum index length

Visual studio code annotation plug-in: korofileheader

A command starts the monitoring journey!
随机推荐
Reading method (three times reading method)
Using the method of combining shapes in illustrator
c#实现callback回调
【C】【时间操作】C语言中关于时间的操作
Retrofit扩展阅读
[DB written interview 367] in the three-level schema structure of the database, the description of all data logical structures and features in the database is ()
4.9 commander. js
Junit5 unit test
Retrofit Extended reading
《网络是怎么样连接的》读书笔记 - FTTH
关于sql的问题:两张表的字段关联问题
Improve code checking with annotations
window10局域网共享文件夹流程
Unity开发相关的博客收集
给两个字符串s和t,判断t是否为s的重新排列后组成的单词
Joking Domain Driven Design (VI) -- Boundary context -- Design
Tidb and MySQL modify system variables / common statements (kill the process in process)
Visual studio code annotation plug-in: korofileheader
Unity . Net framework
Client construction and Optimization Practice