当前位置:网站首页>Prevent cookies from modifying ID to cheat login
Prevent cookies from modifying ID to cheat login
2022-07-27 08:01:00 【Ding Yatao】
When developing a website , Often need to be saved in Cookie Medium id recovery Session Sign in . Malicious users modify Cookie Medium id Spoofing login , for example , In developer mode :

The author designed an automatic re Application session The mechanism of ( See the previous article for details ), When session Be overdue , I can create a new one session life . To prevent modification id, Check code mechanism can be adopted :
(1) Create a check code when logging in :check_key And generate the verification sequence check_code
(2) take id And verification string check_code Save to cookie in , take check_key Save to the user table record field
(3) Need to pass through cookie When restoring web pages , take cookie The authentication string in and stored through the user table check_key Compare the calculated verification string , So as to realize anti deception
(4) because cookie Medium id The verification string is attached , It needs to be cleared when logging in , Prevent text boxes ( set up id by txtUserID) Auto search fill :
$(document).ready(function () {
var c_input = $("#txtUserID").val();
if (c_input.indexOf("|") != -1)
$("#txtUserID").val(c_input.split("|")[0]);
});(5) Verification in web pages :
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 Class to create validation methods
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)
{
// according to cuserid and nkey Generate validation string
......
}边栏推荐
- [applet] how to get wechat applet code upload key?
- 瑞芯微RK3399-I2C4挂载EEPROM的修改案例
- Qt Creator代码风格插件Beautifier
- [applet] the upload of the wechat applet issued by uniapp failed error: error: {'errcode': -10008,'errmsg':'Invalid IP
- 帮个忙呗~不关注不登录,不到一分钟的一个问卷
- linux中mysql表名区不区分大小写
- [flight control development foundation tutorial 4] crazy shell · open source formation UAV - serial port (optical flow data acquisition)
- 如何在电脑端登陆多个微信
- Promise details
- C#winform 窗体事件和委托结合用法
猜你喜欢

What is the real HTAP? (2) Challenge article

How to log in multiple wechat on the computer

How to play with the purchase of SAP variant materials? Look at this article and you will understand
![[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement](/img/28/979dceac1454a3e53409a4feb20320.png)
[day42 literature intensive reading] a Bayesian model of perfect head centered velocity during smooth pursuit eye movement

Lua iterator

Qt Creator代码风格插件Beautifier

Gossip: is rotting meat in the pot to protect students' rights and interests?

10000 word parsing MySQL index principle -- InnoDB index structure and reading

Combined use of C WinForm form form event and delegate

RPC remote procedure call
随机推荐
C语言:优化后的希尔排序
CommonTitleBar hide left right
反弹shell是什么?反弹shell有什么用?
Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
Abstract factory pattern
npm的使用
Usage scenarios for automated testing
The code interface is a little automated
Comprehensive analysis of ADC noise-02-adc noise measurement method and related parameters
Grandson's questions are difficult, and his son's invigilation is strict. I can't do it. Pay back my school money
Demo:pa30 Bank Country Code default CN enhancement
Lua iterator
Lua迭代器
增强:BTE流程简介
Shell script learning day01
linux中mysql表名区不区分大小写
Shell loop exercise
如何在 60 秒内去分析和定位问题?
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform
物来顺应,未来不迎,当时不杂,既过不恋