小女子请高手帮忙(我已经弄了两天了)

lianyi_1999 2004-08-03 09:59:19
想做一个网站后台管理系统,在用户登陆时的代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<meta name = "Author" content=" Zyl">
<meta name = "Contact" content="lianyi_1999@sohu.com">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网站后台管理系统V1.0</title>
</head>
<body>
<form action="Login_submit.asp" method="post">
<center>
<table width="770" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan = "2" height="27" bgcolor = "#E3E3E3"><div align="center"><strong>管理员登陆</strong></div></td>

</tr>
<tr>
<td width="355" height="27">
<div align="right"><font size="2">用户名</font>:</div></td>
<td width="415"><input name="username" type="text" value="" size="20" maxlength="20"></td>
</tr>
<tr>
<td height="27">
<div align="right"><font size="2">密  码</font>:</div></td>
<td><input name="password" type="password" id="password" size="20" maxlength="20"></td>
</tr>
<tr>
<td colspan = "2" height="27" align = "center">
<input name="sumbit" type="submit" value="登录">
    <input name="cancle" type="reset" value="取消"></td>
</tr>
<td colspan = "2" height = "20" bgcolor = "#E3E3E3"></td>
</table>
<center>
</form>
</body>
</html>

其中Login_submit.asp为
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="conn.asp"--> // 是打开数据库
<%
username = request.Form("username")
password = request.Form("password")
Set rs = Server.CreateObject("ADODB.RecordSet")
sql = "select * from Manage_User where UserName='" & username & "' And PassWord='"& password &"'"
Set rs = conn.Execute(sql)
If rs.recordcount=0 Then

Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
conn.Close
Set conn = Nothing
else
response.Redirect("Login.asp")
end if
%>

可是不知道为什么login_submit.asp中的if语句是If rs.recordcount=0 还是If rs.recordcount<>0 都执行then中的内容,
Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
conn.Close
Set conn = Nothing

各位大虾帮忙呀,我是新手,都苦恼好几天了,谢谢了


...全文
234 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
aiguo25 2004-08-04
  • 打赏
  • 举报
回复
rs.recordcount 的值不稳定,应该用rs.eof
Iamnomad 2004-08-03
  • 打赏
  • 举报
回复
If rs.recordcount=0 Then
Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
conn.Close
Set conn = Nothing
else
response.Redirect("Login.asp")
end if

==>

If not rs.eof Then

Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
else
response.Redirect("Login.asp")
end if
conn.Close
Set conn = Nothing

不要用recordcount,好象它和打开方式有关,不记得了,在学JSP




海大富运动 2004-08-03
  • 打赏
  • 举报
回复
呵呵!我做的网站,以现在大家的技术来说,都可以进行sql注入,以前我不懂过滤,现在觉得要看什么样的网站,比如网吧内部的电影播放系统,我都不会过滤,呵呵!至于在外部服务器的web页,我都要过滤很多东西……
cyl180555 2004-08-03
  • 打赏
  • 举报
回复
同意 Gorgee(凭阑悄悄) 的程序,我一直也是这样写的,楼主的写法有可能被别人用 ' " 设计出万能ID和密码, 比如ID 输入 111'or'1=1 密码随便输入 则最后执行的sql语句就成了:
sql = "select * from Manage_User where UserName='111'or'1=1' And PassWord='xxx'"
这就一定能通过验证了原理可查看:http://www.pconline.com.cn/pcedu/empolder/db/sql/0404/346024.html
morris_lz 2004-08-03
  • 打赏
  • 举报
回复
条件就用If not rs.eof Then判断,看看返回的记录集是否为空,不为空就说明有这个用户,注册新用户入库就可以了
blues-star 2004-08-03
  • 打赏
  • 举报
回复
rs的打开方式取得不到recordcount导致的

使用rs.open打开
dotnet东哥 2004-08-03
  • 打赏
  • 举报
回复
看看sql有没有问题
sql = "select * from Manage_User where UserName='" & username & "' And PassWord='"& password &"'"
response.write sql
response.end
dotnet东哥 2004-08-03
  • 打赏
  • 举报
回复
rs.recordcount是不是等于-1呀
54netkey 2004-08-03
  • 打赏
  • 举报
回复
rs.recordcount>0呢?
lianyi_1999 2004-08-03
  • 打赏
  • 举报
回复
如果你要用rs.recordcount来判断的话,你应该每次输出它的值,看看到底是什么原因?
怎样查看记录中的值?
lianyi_1999 2004-08-03
  • 打赏
  • 举报
回复
上面所有的代码我都试过了,还是不行,总是执行if语句中then的内容,不管if是否成立,真的是求求各位大哥,大姐了
19az 2004-08-03
  • 打赏
  • 举报
回复
同意楼上的,如果你要用rs.recordcount来判断的话,你应该每次输出它的值,看看到底是什么原因?
因为你用的是conn.Execute(sql),这样用的rs不支持recordcount属性,故rs.recordcount的值一直为 -1,应该换个方式执行,如 rs.open sql,conn,1,1 等等

Gorgee 2004-08-03
  • 打赏
  • 举报
回复
sql = "select PassWord from Manage_User where UserName='" & username & "'"
Set rs = conn.Execute(sql)
If not rs.eof Then
if trim(rs.fields("PassWord"))=trim(password) then
Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
else
response.Redirect("Login.asp") 'error pwd
end if
else
response.Redirect("Login.asp") 'error userId
end if

conn.Close
Set conn = Nothing
jervis82 2004-08-03
  • 打赏
  • 举报
回复
实践才是最重要。试一试不就知道了,不用问吧。
lianyi_1999 2004-08-03
  • 打赏
  • 举报
回复
我是新手,什么都不懂,能否告诉我什么叫“SQL注入”,谢谢
talkno 2004-08-03
  • 打赏
  • 举报
回复
sql = "select * from Manage_User where UserName='" & username & "'
set rs=server.createobject("adodb.recordset")
rs.open sql,objcn
if rs.eof then
response.Write"用户帐号错误或用户帐号未激活!请重新输入!"
response.Write("<a href=Javascript:history.go(-1)>返回</a>")
response.end
rs.close
set rs=nothing
else
sql = "select * from Manage_User where UserName='" & username & "' And PassWord='"& password &"'"
set rst1=server.CreateObject("adodb.recordset")
rst1.open sql1,objcn,1,3
if rst1.eof then
response.Write"密码错误!请重新输入!"
response.Write("<a href=Javascript:history.go(-1)>返回</a>")
rst1.close
set rst1=nothing
objcn.close
set objcn=nothing
response.End
end if
end if
look4sword 2004-08-03
  • 打赏
  • 举报
回复
if rs.eof and rs.bof then
...
else
...
end if
同意这个.
而且,楼主的程序很容易SQL注入,要改一下哦.
wsdzm 2004-08-03
  • 打赏
  • 举报
回复
Set rs = conn.Execute(sql)--->rs.open sql,conn,1,1
wsdzm 2004-08-03
  • 打赏
  • 举报
回复
rs.open sql,conn,1,1
If rs.recordcount=0 Then


response.Redirect("Login.asp")

else

Session("username")=rs("UserName")
Session("password")=rs("PassWord")
response.Redirect("main.asp")
conn.Close
Set conn = Nothing


end if
甘泉123 2004-08-03
  • 打赏
  • 举报
回复
if rs.eof and rs.bof then
...
else
...
end if

28,409

社区成员

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

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