您的位置:首页 > 资讯攻略 > 急需ASP代码!如何设计index.asp页面实现以下功能?

急需ASP代码!如何设计index.asp页面实现以下功能?

2024-11-26 14:35:07

欢迎来到我们的网站

<%

' 用户登录信息

Dim userName, userPassword, messageText

userName = ""

userPassword = ""

messageText = ""

' 检查表单是否提交

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then

' 获取表单数据

userName = Request.Form("username")

userPassword = Request.Form("password")

' 连接数据库

Dim conn, rs, sql

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/database.mdb;"

' 查询用户信息

sql = "SELECT * FROM Users WHERE UserName = ? AND UserPassword = ?"

Set rs = Server.CreateObject("ADODB.Command")

rs.ActiveConnection = conn

rs.CommandText = sql

rs.Parameters.Append rs.CreateParameter("@p1", 200, 1, 50, userName)

rs.Parameters.Append rs.CreateParameter("@p2", 200, 1, 50, userPassword)

' 执行查询

Set rs = rs.Execute()

' 检查用户是否存在

If Not rs.EOF Then

' 用户存在,显示用户信息

Response.Write "

"

Response.Write "欢迎, " & rs("UserName").Value & "!"

Response.Write "

"

Else

' 用户不存在,显示错误信息

messageText = "用户名或密码错误,请重试。"

End If

' 关闭记录集和连接

rs.Close

Set rs = Nothing

conn.Close

Set conn = Nothing

End If

%>

<%= messageText %>

">

用户名:

密码:

<%

' 显示数据库中的用户列表(仅供管理员参考)

' 注意:以下代码块应在管理员登录验证后使用,出于安全考虑,这里省略验证部分

' Dim adminUser, adminPassword

' adminUser = "admin"

' adminPassword = "admin123"

' If userName = adminUser And userPassword = adminPassword Then

' 重新连接数据库

' Set conn = Server.CreateObject("ADODB.Connection")

' conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/database.mdb;"

' 查询所有用户

' sql = "SELECT * FROM Users"

' Set rs = Server.CreateObject("ADODB.Recordset")

' rs.Open sql, conn

' 显示用户列表

' Response.Write "

用户列表

"

' Response.Write "

' Response.Write "

用户名密码"

' Do Until rs.EOF

' Response.Write "

"

' Response.Write "

" & rs("UserName").Value & ""

' Response.Write "

" & rs("UserPassword").Value & ""

' Response.Write "

"

' rs.MoveNext

' Loop

' Response.Write "

"

' 关闭记录集和连接

' rs.Close

' Set rs = Nothing

' conn.Close

' Set conn = Nothing

' End If

%>

相关下载