当前位置: 首页 > 图文教程 > 网络编程 > ASP > 用密码保护页面 (II)

ASP
在ASP应用中验证用户身份(2)
在ASP应用中验证用户身份(3)
在ASP应用中验证用户身份(4)
在ASP应用中验证用户身份(5)
用ASP开发一个在线考试程序(一)
用ASP开发一个在线考试程序(二)
用ASP开发一个在线考试程序(三)
用ASP开发一个在线考试程序(四)
用表单来提交sql - 1
用表单来提交sql - 2
用表单来提交sql - 3
让您的主页支持各种浏览设备(ASP+篇)(上)
如何用ASP编写网站统计系统(一)
如何用ASP编写网站统计系统(二)
如何用ASP编写网站统计系统(三)
如何用ASP编写网站统计系统(四)
一个免费的邮件列表源程序(一)
一个免费的邮件列表源程序(二)
一个免费的邮件列表源程序(三)
用密码保护页面 (I)

ASP 中的 用密码保护页面 (II)


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 36 ::
收藏到网摘: n/a

  英文原文


现在我们创建查询语句,可以验证在表单中输入的内容是否与数据库中的内容相一致。

<%@ Language=VBScript %>
<% Response.Buffer = True %>

<HTML>
<BODY>

<% Session("allow") = True %>

<%
UserName = Request.Form("username")
Password = Request.Form("password")
'grab the form contents

Set MyConn=Server.CreateObject("ADODB.Connection")
MyConn.Open "your connection string here"

SQL = "Select * From tblLogin"
Set RS = MyConn.Execute(SQL)

If UserName = RS("UserName") AND Password = RS("Password") Then
'if there is a match then show the page
%>


Put the contents of your page here.

<%
Else
Response.Redirect "http://www.yourdomain.com/login.asp"
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
End If
%>
'if there was no match then make the visitor try again to login.

</BODY>
</HTML>


把含上述代码的文件命名为login.asp