当前位置:网站首页>session-cookie与token
session-cookie与token
2022-07-02 06:41:00 【大鸡腿最好吃】
session-cookie
利用服务器的session和浏览器的cookie来实现前后端认证的,在服务器创建的session集合,将同一个客户端的请求都维护在各自的session中,每当服务器接收到浏览器的cookie请求时,会在session集合中查询对应的s_id,如果有就确认身份成功。

缺点:
服务端需要存储Session,并且由于Session需要经常快速查找,通常存储在内存或内存数据库中,同时在线用户较多时需要占用大量的服务器资源。
易受到CSRF攻击:基于cookie的一种跨站伪造攻击,基于cookie来进行识别用户的话,用户本身就携带了值,cookie被截获,用户就很容易被伪造;
扩展不好:当需要扩展时,创建Session的服务器可能不是验证Session的服务器,所以还需要将所有Session单独存储并共享。
Token认证
Token验证也叫令牌,是一种无状态身份验证方式,不用将用户信息存在服务器或Session中去除了服务器内耗问题;当用户第一次登录时,服务器生成一个token并返回客户端,除用户端将保存的token失效或者删除之外,在接下来的请求时,只要带着这个令牌请求数据即可。
1.用户通过用户名和密码发送请求;
2.程序验证;
3.程序返回一个签名的token 给客户端;
4.客户端储存token,并且每次请求都会附带它;
5.服务端验证token并返回数据。
优点
- 服务端不需要存储和用户鉴权有关的信息,鉴权信息会被加密到Token中,服务端只需要读取Token中包含的鉴权信息即可。
- 避免了共享Session导致的不易扩展的问题。
- 不需要依赖Cookie,有效的避免Cookie带来的CSRF攻击问题
- 使用CORS可以快速解决跨域问题。
边栏推荐
- 虚幻材质编辑器基础——如何连接一个最基本的材质
- Project practice, redis cluster technology learning (11)
- [illusory] weapon slot: pick up weapons
- Blender camera surround motion, animation rendering, video synthesis
- [illusory] automatic door blueprint notes
- [Lua] summary of common knowledge points (including common interview sites)
- Commutateur Multi - lentilles Blender
- What is call / cc- What is call/cc?
- How to judge the quality of primary market projects when the market is depressed?
- Allure -- common configuration items
猜你喜欢

Understand the composition of building energy-saving system
![[illusory] weapon slot: pick up weapons](/img/a7/1e395fc9cdfd0359e7ae4d2313290d.png)
[illusory] weapon slot: pick up weapons

STM32 and motor development (upper system)

虛幻AI藍圖基礎筆記(萬字整理)
Brief analysis of edgedb architecture
What is the relationship between realizing page watermarking and mutationobserver?
![[ue5] blueprint making simple mine tutorial](/img/87/d0bec747a6b6276d63a315f88745ec.png)
[ue5] blueprint making simple mine tutorial

pytest框架实现前后置

Applet development summary

Postman--使用
随机推荐
ue虛幻引擎程序化植物生成器設置——如何快速生成大片森林
ue虚幻引擎程序化植物生成器设置——如何快速生成大片森林
Mock Server基本使用方法
Blender摄像机环绕运动、动画渲染、视频合成
Solutions to a series of problems in sqoop job creation
2021-10-02
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
SQOOP 1.4.6 INSTALL
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
合并有序数列
Deep understanding of redis cache avalanche / cache breakdown / cache penetration
Blender模型导入ue、碰撞设置
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
This article takes you to learn in detail what is fiber to home FTTH
【虚幻4】UMG组件的简介与使用(更新中...)
SAP Spartacus express checkout design
07数据导入Sqoop
[unity3d] nested use layout group to make scroll view with dynamic sub object height
webUI自动化学习
Blender海洋制作