当前位置:网站首页>Generally speaking, cookies, sessions, and tokens are different
Generally speaking, cookies, sessions, and tokens are different
2022-07-16 07:31:00 【Vision-wang】
1.Cookie
Save in browser The first stage : Cookie It stores the user's original user name and password , Every time you access the server , The browser carries the saved user name and password Cookie, There is a server to parse and verify whether the user name and password match , If it matches, you don't need to log in again But not very safe , If hackers get complete Cookie You can get the complete user name and password The second stage : Cookie It's very unsafe to store the user's original user name and password , And it happens that the server generates a unique SessionID And return to the browser , So browser Cookie I can save it SessionID And through Session The validity period of is set to Cookie The expiration time of , It's solved Cookie The great danger of releasing completed information The third stage : Cookie Inside the store Token, Compared with phase II, this method has no improvement for browsers , The improvement is that the server is easier for storage
2.Session
Session After the user verifies the user name and password , If the validation is successful , The server will generate a unique Session ID and Session ID The expiration time of , And will the Session Put it in the database , When the expiration time is reached, it will be cleared automatically After the server is generated, the server is saved , How does the client exist ? Put this SessionID And expired to the browser , Handled by the browser , Hence the Cookie The second stage
3.Token
Session Larger in volume , When there are more users , Server for Session The storage of may be under pressure Therefore, we don't want the server to store so much Session data , So it came out Token, Our server only needs to define a ciphertext , such as abcde, Each user logs in , All servers use the same abcde+ User name, password + The encryption algorithm generates a signature , This signature is Token, And then Token Send to browser , The browser will Token Can be stored in Cookie It can also be stored in Storage in , Please bring it next time , In this way, the server only needs to store abcde, It's easy
4.JWT
Json Web Token: JWT yes Token The concrete realization of
Token There is no regulation on the type of data transmitted , And encryption algorithms , What format is the data encrypted by the encryption algorithm , Just abstracted Token What is the process of using , What are the processes , such as Token It can be a string , It can also be a row of arrays 6 by 18 Bits, etc
that JWT Namely Token A concrete realization of ,JWT Will be with JSON The encrypted form is saved in the client's , And the encryption algorithm is also specified as HMAC【 Hash message verification code ( symmetry )】,RSASSA【RSA Signature algorithm ( Asymmetric )】,ECDSA【 Elliptic curve data signature algorithm ( Asymmetric )】 Three , The final data is also specified as header (Header)、 Payload (Payload) And signature (Signature) Three parts .
After the user logs in , Generated by the server JWT, And will JWT Send it to the browser , The browser stores the complete Token, Server only stores Token The signed ciphertext browser will Token Can be stored in Cookie It can also be stored in Storage in
边栏推荐
猜你喜欢

六、数据备份软件的配置实验报告

Shut up that thing

Leetcode lecture - 1 Sum of two numbers (difficulty: simple)

Go seckill system 3 -- work mode, publish mode

Leetcode lecture - 1217 Play chips (difficulty: simple)

2021-11-13攻防世界做题记录01MISC

Unity foundation to getting started - Navigation

从功能测试到自动化测试,实现薪资翻倍,我整理的超全学习指南【附学习笔记】

Basic knowledge of redis - rookie tutorial
![From function test to automatic test, to double the salary, I collated the super complete learning guide [with learning notes]](/img/59/dfc87939871832548acecc8ef1d2bf.jpg)
From function test to automatic test, to double the salary, I collated the super complete learning guide [with learning notes]
随机推荐
SAP Tables 透明表、视图(持续更新)
SAP BW 抽取层错误S:AA 821 (bukrs)
Type erase & bridge method
[sword finger offer] special summary of linked list
SAP T-CODE 事务码集(持续更新)
SAP ABAP BAPI_MATERIAL_AVAILABILITY 查询可用库存
[learning records on June 5]
redis基础知识——菜鸟教程
One way linked list implements queue and stack
一、磁盘数据恢复实验报告
Unity3d ray
When byte hung up, the interviewer asked me DDD, but I didn't know
Leetcode lecture - 1217 Play chips (difficulty: simple)
三栏布局的实现方式,(一般要求尽可能多写)
Bucket sorting + drawer principle
From function test to automatic test, to double the salary, I collated the super complete learning guide [with learning notes]
SAP ABAP SMOD&CMOD 二代增强遇到的问题
【LeetCode】面试题 01.05. 一次编辑
求职3个月,简历大多都石沉大海,一说是手工测试都连连摇头~太难了
IO multiplexing