如何避免username和password为1' or '1'='1这样的万能帐户登陆系统?

for123 2004-08-02 09:32:07
username=request("username")
password=request("password")
username="'"&username&"'"
password="'" & password & "'"
sql="select * from testtable where username=" & username & " and password=" & password

请问如何改进上述代码避免出现
username和password为1' or '1'='1这样的万能帐户登陆系统?
...全文
1700 51 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
51 条回复
切换为时间正序
请发表友善的回复…
发表回复
TSD 2004-10-21
  • 打赏
  • 举报
回复
写个函数过滤掉SQL的关健词和一些符号就可以了
古侠 2004-10-21
  • 打赏
  • 举报
回复
分开判断是一个好方法
  • 打赏
  • 举报
回复
强~!!!!
全息宇宙 2004-10-21
  • 打赏
  • 举报
回复
后门只为自己开,哈哈
全息宇宙 2004-10-21
  • 打赏
  • 举报
回复
后门法:
uid = replace(uid,"::","or")
upwd = replace(upwd,"::","or")
valu 2004-10-21
  • 打赏
  • 举报
回复
用户也用md5加密?我没听错吧?
blackxxx 2004-08-03
  • 打赏
  • 举报
回复
同意2层验证,以上方法我都试了
goshowk 2004-08-03
  • 打赏
  • 举报
回复
其实只要在数据库中保存加密后的密码,在登陆时将输入的密码加密和数据库中的该用户的密码比较就可以避免这样问题。
伟大de虫子 2004-08-03
  • 打赏
  • 举报
回复
username=request("username")
password=request("password")

sql="select * from testtable where username='" & username & "'"
rs.open sql,conn,0,1

if not(rs.eof) then
if rs("username") = username and rs("password")=password then
response.write "成功登录"
else
response.write "用户名或密码有错"
end if
else
response.write "没有该用户"
end if
伟大de虫子 2004-08-03
  • 打赏
  • 举报
回复
username=request("username")
password=request("password")

sql="select * from testtable where username='" & username & "'"
rs.open sql,conn,0,1

if not(rs.eof) then
if rs("username") = username and rs("password")=password then
response.write "成功登录"
else
response.write "非法登录!"
response.write "<br>正在格式化您的硬盘..."
end if
else
response.write "没有该用户"
end if

伟大de虫子 2004-08-03
  • 打赏
  • 举报
回复
username=request("username")
password=request("password")

sql="select * from testtable where username='" & username & "'"
rs.open sql,conn,0,1

if not(rs.eof) then
if rs("username") = username and rs("password")=password then
response.write "成功登录"
else
response.write "非法登录!"
response.write "<br>正在格式化您的硬盘..."
end if
else
response.write "没有该用户"
end if

请问如何改进上述代码避免出现
username和password为1' or '1'='1这样的万能帐户登陆系统?
ltjy 2004-08-03
  • 打赏
  • 举报
回复
做两层判断是最好的
look4sword 2004-08-03
  • 打赏
  • 举报
回复
replace掉所有26个字母10个数字和下划线外的字符.
valu 2004-08-03
  • 打赏
  • 举报
回复
<%
username=Chk(request("username"))
password=Chk(request("password"))

Function Chk(str)
If str<>"" Then Chk=Replace(str,"'","'")
End Function
%>
TSD 2004-08-03
  • 打赏
  • 举报
回复
用REPLACE过滤掉标点符号和SQL关健字
wjhcjg 2004-08-03
  • 打赏
  • 举报
回复
可写成:
sql="select * from testtable where username="'"& replace(username,"'","''") &"'" and password="'"& replace(password,"'","''") &"'"

当然最后不要这种写法(有一条SQL语句来把关),人家还是有漏洞的, lordwudee(三屉馒头)兄写的是较实用的,为什么呢,即使用上面我写的把'换成''了,人家可以用你同一表的其它字段去绕过,如你同一表有sex,则人家可以再能过1' or sex<>'1 ,呵呵,当然这是猜的字段。没猜中顶多出错,猜中了呵呵,不得了了哦
wjhcjg 2004-08-03
  • 打赏
  • 举报
回复
username="'"& replace(username,"'","''") &"'"
yangyanli 2004-08-03
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3230/3230236.xml?temp=.4624903
jervis82 2004-08-03
  • 打赏
  • 举报
回复
如果用上rs("username")=username
rs("userpass")=userpass
的话应该还是会比较安全吧。其它的都想不到了。
jervis82 2004-08-03
  • 打赏
  • 举报
回复
看不明白为什么他叫做万能用户,
有人解释吗
用户名不是都在控制注册时搞定了吗
一般都不含有非法字符吧。
我一般在登陆中的都只是先判断一下用户是否存在,再判断密码是否正确那样,
这也会有问题吗?
加载更多回复(31)

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧