当前位置:网站首页>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可以快速解决跨域问题。
边栏推荐
- 【教程】如何让VisualStudio的HelpViewer帮助文档独立运行
- Stm32 et développement de moteurs (système supérieur)
- Database -- acid of transaction -- introduction / explanation
- 使用Windbg静态分析dump文件(实战经验总结)
- 传输优化抽象
- Blender石头雕刻
- 两数之和,求目标值
- MongoDB-快速上手MongoDB命令行的一些简单操作
- Blender stone carving
- AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
猜你喜欢
虚幻AI蓝图基础笔记(万字整理)
MPLS experiment
Following nym, the new project Galaxy token announced by coinlist is gal
UE5——AI追逐(藍圖、行為樹)
Introduction and Principle notes of UE4 material
【JetBrain Rider】构建项目出现异常:未找到导入的项目“D:\VisualStudio2017\IDE\MSBuild\15.0\Bin\Roslyn\Microsoft.CSh
Solutions to a series of problems in sqoop job creation
Ue5 - AI pursuit (blueprint, behavior tree)
Sum the two numbers to find the target value
Blender ocean production
随机推荐
两数之和,求目标值
Stm32 et développement de moteurs (système supérieur)
Metaclass type and using metaclass to implement model class ORM
Understand the composition of building energy-saving system
[unity3d] cannot correctly obtain the attribute value of recttransform, resulting in calculation error
ERROR 1118 (42000): Row size too large (> 8126)
07 data import sqoop
Spatial interpretation | comprehensive analysis of spatial structure of primary liver cancer
Blender camera surround motion, animation rendering, video synthesis
sqoop创建job出现的一系列问题解决方法
[unreal] animation notes of the scene
网络通信学习
Determine whether there are duplicate elements in the array
Aiphacode is not a substitute for programmers, but a tool for developers
[tutorial] how to make the Helpviewer help document of VisualStudio run independently
Postman -- use
【Unity3D】无法正确获取RectTransform的属性值导致计算出错
MPLS experiment
Nonlinear optimization: steepest descent method, Newton method, Gauss Newton method, Levenberg Marquardt method
Project practice, redis cluster technology learning (12)