当前位置:网站首页>防止Cookie修改id欺骗登录
防止Cookie修改id欺骗登录
2022-07-27 06:59:00 【丁亚涛】
在开发网站时,经常需要通过保存在Cookie中的id恢复Session登录。恶意用户通过修改Cookie中的id欺骗登录,例如,在开发者模式下:

笔者设计了自动重新申请session的机制(具体见前期文章),当session过期,可以创建新的session续航。为了防止修改id,可以采用校验码机制:
(1)登录时创建校验码:check_key并生成验证序列check_code
(2)将id和验证串check_code保存到cookie中,将check_key保存到用户表记录字段中
(3)需要通过cookie恢复网页时,将cookie中的验证串和通过用户表存储的check_key计算出来的验证串作比对,从而实现防欺骗
(4)由于cookie中的id附加了验证串,在登录时需要清除,防止文本框(设id为txtUserID)自动搜索填充:
$(document).ready(function () {
var c_input = $("#txtUserID").val();
if (c_input.indexOf("|") != -1)
$("#txtUserID").val(c_input.split("|")[0]);
});(5)网页中的验证:
HttpCookie readcookie = Request.Cookies["userID"];
string[] a_uid = readcookie.Value.ToString().Split('|');
string cuid = a_uid[0];
string ccheck = a_uid[1];
if (Users.CookieCheck(cuid, ccheck) == false) Response.Redirect("login.aspx");(6)Users类创建验证方法
public bool CookieCheck(string cuserid, string ccheckstring)
{
DataBase DB = new DataBase();
string sql = "select user_check from users where USERID='" + cuserid + "'";
DataSet ds = DB.GetDataSetSql(sql);
if (ds.Tables[0].Rows.Count <= 0)
{
return false;
}
else
{
string c_user_check = ds.Tables[0].Rows[0].ItemArray[0].ToString();
if (String.IsNullOrEmpty(c_user_check) || c_user_check.ToLower()=="null") return false;
int nkey = int.Parse(ds.Tables[0].Rows[0].ItemArray[1].ToString());
if (ccheckstring == CreateCookieCheck(cuserid, nkey))
return true;
else
return false;
}
}
public string CreateCookieCheck(string cuserid, int nkey)
{
//根据cuserid和nkey生成验证串
......
}边栏推荐
- Analysis of memory structure of C program code
- Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation
- (2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)
- 冰冰学习笔记:类与对象(中)
- Multi condition query of when
- C winfrom common function integration-2
- 【StoneDB Class】入门第一课:数据库知识科普
- 杂谈:最近好多朋友谈出国……
- Prior Attention Enhanced Convolutional Neural Network Based Automatic Segmentation of Organs at Risk
- Port forwarding summary
猜你喜欢

(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)

A small cotton padded jacket with air leakage

Chapter 6 Shell Logic and Arithmetic

Actual combat of flutter - Request encapsulation (I)

海康h9摄像头用xshell无法连接(没有启用ssh)

Okaleido ecological core equity Oka, all in fusion mining mode

C language implementation of guessing numbers Games project practice (based on srand function, rand function, switch statement, while loop, if condition criterion, etc.)

一体化实时HTAP数据库StoneDB,如何替换MySQL并实现近百倍分析性能的提升

Bingbing's learning notes: classes and objects (middle)

JS make a traffic light
随机推荐
VLAN trunk实验
sql语句批量更新 时间减去1天
Help send a recruitment, base all over the country. If you are interested, you can come and have a look
MySQL backup strategy
The error of QT connecting SQLite database and its modification
Li Mu hands-on learning, in-depth learning, V2 transformer and code implementation
单元测试系统化讲解之Mockito
帮忙发一份招聘,base全国,有兴趣的可以过来看看
Gossip: Recently, many friends talk about going abroad
Closed hash and open hash resolve hash conflicts
SQLite common function integration
Tcp/ip protocol analysis (tcp/ip three handshakes & four waves + OSI & TCP / IP model)
Flink1.14 SQL basic syntax (I) detailed explanation of Flink SQL table query
Oracle cleans up the Database disk space of tables with referenced partitions
yhb_ sysbench
(2022 Hangdian multi school III) 1011.taxi (Manhattan maximum + 2 points)
Top ten interview questions for software testing (with answers and analysis)
ARP广播实践案例
Cadence (XI) silk screen printing adjustment and subsequent matters
Codeforces Round #810 (Div.2) A-C