日期:2009-09-13  浏览次数:21106 次

嘻嘻,虽然是英文的,但是很简单,我想大家都能看懂^-^
Active Server Pages    

Password Script    
<%
Sub FormInput() %>
<form method=post action="LOGOn.ASP">
<center>
<H1>Generic LOGOn</H1>
User Name:<input type=text size=20 name=username>
<br><br>
Password:<input type=password size=20 name=password>
<br><br>
<input type=submit name=submit value="Submit">
</center>
</form>
<% End Sub %>
<!--#include file="adovbs.inc" -->

<%
' *********** Password Login Code *********************
' *********** programmed by Robert Robbins ************
' *********** First Version 03/28/99 ******************
' *****************************************************
' Call Input Form subroutine
FormInput()

' Create session variable. Username needed for filename.ASP
Session("user") = ""

' Initialize boolean flags to false
correct_name = False
correct_password = False

' Connect to table in database
Set cn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
cn.Open "DSN Name"
rs.Open "Select * From TableName",cn,adOpenStatic,adLockPessimistic

' Test for correct username and password
If Request.Form("submit") > "" Then
Do While Not rs.EOF
' Compare form input to password database recordset values
If Request.Form("username") = rs("username") Then
correct_name = True
End If
If Request.Form("password") = rs("password") Then
correct_password = True
End If
rs.MoveNext
Loop

If correct_password = True And correct_name = True Then
' If password and username are correct, jump to DataEntry.ASP
' Note: chr(34) is the double quotes character
                Session("user") = Request.Form("username")
Response.write "<Script Language=" & chr(34) & "javascript" & chr(34) & ">"
Response.write "window.location = " & chr(34) & "DataEntry.ASP" & chr(34) & """
Response.write "</Script>"
Else
' If password or username is incorrect, write javascript code in HTML for an alert
dialog box
Response.write "<Script Language=" & chr(34) & "javascript" & chr(34) & ">"
Response.write "alert(" & chr(34) & "Access Denied!" & chr(34) & ");"
Response.write "</Script>"
End If
rs.Close
End