用密码保护页面 (II)

英文原文

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

1@ Language=VBScript 
1 Response.Buffer = True 
1<html>
2<body>   
3  

Session("allow") = True

1  

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

1  
2  
3Put the contents of your page here.   
4  

Else
Response.Redirect "http://www.yourdomain.com/login.asp"
RS.Close
MyConn.Close
Set RS = Nothing
Set MyConn = Nothing
End If

1'if there was no match then make the visitor try again to login.   
2  
3</body>
4</html>

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

Published At
Categories with Web编程
Tagged with
comments powered by Disqus