中大新华学院东莞校区:asp中多用户登陆

来源:百度文库 编辑:神马品牌网 时间:2024/05/09 09:53:15
请问在login登录的时候,有很多用户和密码单纯用 set rs=server.createobject("adodb.recordset")
sql="select * from admin where 密码='"&password&"' and 用户名='"&username&"'"
rs.open sql,conn,1,3
这样的选择办法,就可能会出现使用1号用户的用户名+2号用户的密码就能登录的情况!
请问如何解决?
如果我1号用户是管理员,2号用户是客人,在后面的显示报表的网页中有一个“修改”超链接(能够跳转到修改的asp中)但这个超链接只能让1号管理员去点击2号用户点不了或者看不见,应该怎么办?

不会啊...
每次读取的都是同一条记录..
不会重复读取的...

如果你觉得不安全,可以试试这样子
...
sql="select top 1 * from admin where 用户名='"&username&"'"
rs.open sql,conn,1,1
if rs.eof then
.... '用户名不存在
elseif rs("密码")<>password then
... '''密码错误
else
... '正常,可登录
end if

这样的SQL写法虽然不好,但是怎么会出现“使用1号用户的用户名+2号用户的密码就能登录的情况”呢?

注意SQL语句里面是“and”不是“or”

set rs=server.createobject("adodb.recordset")
sql="select * from admin where 用户名='"&username&"' and 密码='"&password&"'"
rs.open sql,conn,1,3

SQL语句的问题,条件先查询用户在查询用户密码...用户名是唯一的而密码则不是,用户1可以和用户2的密码相同,但用户1的用户名不能和用户2的用户名相同

摘抄一段供你参考
<%
'If the user has filled out the form and pressed the submit button
IF request.querystring("step") = "2" THEN

'Open a new database connection
adoCon.Open cstring

'Take values from the form
str_Username = Request.Form ("username")
str_Password = Request.Form ("password")

'Create new SQL string
strSQL = "SELECT code " & _
"FROM tbl_Authors WHERE name = '" & str_Username & "' AND Password = '" & str_Password & "'"

'Create a new recordsheet
Set rs_login = Server.CreateObject ("ADODB.RecordSet")

'Open the record sheet and execute SQL
rs_login.open strSQL,adoCon

'If the username and password combination does not exist then redirect the user
If rs_login.EOF _
Or rs_login.BOF Then
Response.Redirect "badlogin.asp"
Else
'Write the user code to the cookie
Response.Cookies("Login")("userCode") = rs_login("code")
'Redirect to main page
Response.redirect("main.asp")
End If
End if
%>