asp 用户登陆问题--学习中

来源:百度知道 编辑:UC知道 时间:2024/05/30 19:42:41
表单 yonghu 对应的项有 zhanghao, ....mima,
<%
dim zhanghao,mima
set con=server.createobject("adodb.connection")
con.open "filedsn=C:\Program Files\Common Files\ODBC\abc.dsn"
zhanghao=Request("i")
mima=Request("p")
con.execute(" select zhanghao from yonghu where zhanghao='"&zhanghao&"' and mima='"&mima&"'")
if mima<>mima then
Response.Write"您输入的密码错误"
if mima=mima then
Response.Write"登陆成功"
end if
%>
想完成个简单的登陆,真是越搞越郁闷,晕了,
特别是怎么获得数据库的帐号和密码与填写的进行对比
小弟万分感谢!先给30分,如果非常满意追+10分
希望能找个长期能帮我解答问题的朋友~!做课程设计

需要用结果集对象,具体如下:
username=request.Form("username") //括号中的是表单中文本框的名称
password=request.Form("password")//同上
set res,flag;
flag=false;
Set res=Server.CreateObject("ADODB.RecordSet")
res.open "Select * from 数据库表名",con,2,3
if res.eof<>true then
do
if res.fields("username")=username and res.fields("password")=password then //括号中的是数据库中表的列名
flag=true
exit do
end if
res.movenext
loop until res.eof=true
if flag=true then
response.write("登陆成功")
else
response.write("用户名或密码错误")
end if
else
response.Redirect "main.asp?msg=用户名不存在"
end if

不知你能否看懂

这是一个典型的有sql注入漏洞的登录入口

但是这是不能验证用户与密码的
因为在f mima<>mima then这一句有问题
mima是永远等于mima的,就像1=1是永真式一样
所以你的登录入口无论用什么用户名与密码都可以登录
我们要根据zhanghao和mima来取得数据库中的记录
用这条记录来比较表单提交的用户名与密码
一致就通过,