All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP中用正则表达式验证中文的问题_php资料_编程技术
asp.net,URL传值出现错误解决_[Asp.Net教程]
如何在十天学内会php之第九天_[PHP教程]
SQL server存储过程初探_[SQL Server教程]
用php简单实现Search Engine Friendly的URL_[PHP教程]
C#网络应用编程基础练习题与答案(四)_.net资料_编程技术
C#类的声明方法_[Asp.Net教程]
SQL,Server中读取XML文件的简单做法_[SQL,Server教程]
在系统中生成Excel流并传给用户_[Asp.Net教程]
网页制作应掌握技术:随心所欲定制页面"弹出窗口"_JavaScript技术_编程技术
Reading number is top 10 pictures
A man's favorite things14
邪恶搞笑内涵图
超级大兔子
Wild animals melee moment of life and death1
Ashlynn Brooke show proud chest measurement2
Chinese paper-cut grilles art appreciation6
人美胸美腿更美1
这两天,中国人民到处都可以“看海”了
The money of more than 100 countries and regions16
China's programmers are live what kind, had a look at will know that
Download software ranking
Sora aoi, the nurse, uniform ,nursing assistant
Proficient in Eclipse
功夫熊猫2(下集)
Boxer Classic video3
Boxer Classic video1
matrix2
功夫熊猫2(上集)
DreamWeaver8
致我们终将逝去的青春
Eclipse-CALMSANNY (second edition)
归海一刀 published in(发表于) 2014/1/30 1:58:15 Edit(编辑)
防网站登陆被破解的简单方法_[Asp.Net教程]

防网站登陆被破解的简单方法_[Asp.Net教程]

防网站登陆被破解的简单方法_[Asp.Net教程]
在大多数的基于数据库的身份认证登陆模块,大多数的程序员只是用一个简单的SQL查询语句来实现,这样很容易被用户以简单的( 1’ or ’1’=’1 )查询替换给破解.其实只要稍微的修改一下代码,便可以防止.具体请参看以下两个函数的实现:
以下代码基于C#,数据库为Access
1. 未防止 1’ or ’1’=’1 替换的情况:

private bool ValidateUser(string LoginId, string LoginPwd)
{
bool isCorrect = false;

try
{
DBAccept.conn.Open();

string sql = String.Format("select UserName from UserManagement where [UserName]=’{0}’ and [Password]=’{1}’", LoginId, LoginPwd);

OleDbCommand command = new OleDbCommand(sql, DBAccept.conn);

if (command.ExecuteReader().HasRows)
{
isCorrect = true;
}
else
{
isCorrect = false;
MessageBox.Show("此管理员用户不存在或者密码错误,请重试", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("操作数据库出错", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
DBAccept.conn.Close();
}

return isCorrect;
}

2.修正版,可正常阻止 1’ or ’1’=’1 登陆
private bool ValidateUser(string LoginId, string LoginPwd)
{
bool isCorrect = false; //定一个bool变量
try
{
DBAccept.conn.Open();

string sql = String.Format("select Password from UserManagement where [UserName]=’{0}’", LoginId);
OleDbCommand command = new OleDbCommand(sql, DBAccept.conn);
if (command.ExecuteScalar().ToString() == LoginPwd)
{
isCorrect = true;
}
else
{
isCorrect = false;
MessageBox.Show("此管理员用户不存在或者密码错误,请重试", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("操作数据库出错", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
DBAccept.conn.Close();
}
return isCorrect;
}


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.