=====================================
ximalaya登录实例
huangweilu@163.net
huangweilu@Msn.com
=====================================
注意先建立一个插入表单,然后除了密码不做插入绑定以外其他的都可绑定
●代码特别注释
图1
图2
图3
●全部代码如下:
1.注册页-----------------------------------------------------------
CODEPAGE="936"%>
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction =
CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "")
Then
MM_editAction = MM_editAction & "?"
& Request.QueryString
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
' *** Redirect if username exists
MM_flag="MM_insert"
If (CStr(Request(MM_flag)) <> "")
Then
MM_dupKeyRedirect="Reg.asp"
MM_rsKeyConnection=MM_Test_STRING
MM_dupKeyUsernameValue = CStr(Request.Form("User_name"))
MM_dupKeySQL="SELECT User_name FROM Reg WHERE User_name='"
& MM_dupKeyUsernameValue &
"'"
MM_adodbRecordset="ADODB.Recordset"
set MM_rsKey=Server.CreateObject(MM_adodbRecordset)
MM_rsKey.ActiveConnection=MM_rsKeyConnection
MM_rsKey.Source=MM_dupKeySQL
MM_rsKey.CursorType=0
MM_rsKey.CursorLocation=2
MM_rsKey.LockType=3
MM_rsKey.Open
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1,MM_dupKeyRedirect,"?") >= 1) Then
MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar
& "requsername=" &
MM_dupKeyUsernameValue
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%>
' *** Insert Record: set variables
'特别注释图1
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_Test_STRING
MM_editTable = "Reg"
MM_editRedirectUrl = "index.asp"
MM_fieldsStr = "User_namevalue"
MM_columnsStr = "User_name',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "")
MM_columns = Split(MM_columnsStr, "")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And
Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And
Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?"
& Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl &
"&" & Request.QueryString
End If
End If
End If
%>
' *** Insert Record: construct a sql insert statement and execute
it
'特别注释图2
Dim MM_tableValues
Dim MM_dbValues
if(Request.Form("Pass_word") <> "")
then Command1__VarP = md5(Request.Form("Pass_word"))
If (CStr(Request("MM_insert")) <> "")
Then
' create the sql insert statement
MM_tableValues = ""
MM_dbValues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''")
& "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields))
Then
MM_tableValues = MM_tableValues & ","
MM_dbValues = MM_dbValues & ","
End If
MM_tableValues = MM_tableValues &
MM_columns(MM_i)
MM_dbValues = MM_dbValues & MM_formVal
Next
'特别注释图3
MM_editQuery = "insert into " & MM_editTable
& " (" & MM_tableValues
& ", Pass_word) values (" &
MM_dbValues & ",'" + Replace(Command1__VarP, "'",
"''") + "') "
If (Not MM_abortEdit) Then
' execute the insert
Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_editConnection
MM_editCmd.CommandText = MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
If (MM_editRedirectUrl <> "")
Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_Test_STRING
Recordset1.Source = "SELECT * FROM Reg"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
Dim Repeat1__numRows
Dim Repeat1__index
Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
无标题文档action=""
name="form1">
align="center">注册
nowrap>User_name: | size="12"> |
align="right">Pass_word: | type="text" name="Pass_word" value="" size="12"> |
value="插入记录"> onClick="MM_goToURL('parent','index.asp');return document.MM_returnValue" value="登录"> |
value="form1">
cellpadding="3" cellspacing="1"
bgcolor="#999999">
用户密码While ((Repeat1__numRows <> 0) AND
(NOT Recordset1.EOF))
%>
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
Recordset1.Close()
Set Recordset1 = Nothing
%>
2.登陆页------------------------------------------------------
CODEPAGE="936"%>
' FileName="Connection_ado_conn_string.htm"
' Type="ADO"
' DesigntimeType="ADO"
' HTTP="true"
' Catalog=""
' Schema=""
Dim MM_Test_STRING
MM_Test_STRING = "Driver={Microsoft Access Driver (*.mdb)}; DBQ="
& Server.MapPath("test.mdb")
%>
' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then
MM_LoginAction = MM_LoginAction + "?" + Request.QueryString
MM_valUsername=CStr(Request.Form("User_name"))
If MM_valUsername <> "" Then
MM_fldUserAuthorization=""
MM_redirectLoginSuccess="index.asp?info=登录成功!"
MM_redirectLoginFailed="index.asp?info=登录失败!"
MM_flag="ADODB.Recordset"
set MM_rsUser = Server.CreateObject(MM_flag)
MM_rsUser.ActiveConnection = MM_Test_STRING
MM_rsUser.Source = "SELECT User_name, Pass_word"
If MM_fldUserAuthorization <> "" Then
MM_rsUser.Source = MM_rsUser.Source & ","
& MM_fldUserAuthorization
MM_rsUser.Source = MM_rsUser.Source & " FROM Reg
WHERE User_name='" &
Replace(MM_valUsername,"'","''") &"' AND
Pass_word='" &
Replace(Request.Form("Pass_word"),"'","''") &
"'"
MM_rsUser.CursorType = 0
MM_rsUser.CursorLocation = 2
MM_rsUser.LockType = 3
MM_rsUser.Open
If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then
' username and password match - this is a valid user
Session("MM_Username") = MM_valUsername
If (MM_fldUserAuthorization <> "")
Then
Session("MM_UserAuthorization") =
CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
Else
Session("MM_UserAuthorization") = ""
End If
if CStr(Request.QueryString("accessdenied"))
<> "" And true Then
MM_redirectLoginSuccess = Request.QueryString("accessdenied")
End If
if (MM_rsUser.Fields.Item("User_name").Value) = MM_valUsername AND
(MM_rsUser.Fields.Item("Pass_word").Value) =
Request.form("Pass_word") then '判断用户名和密码是否与输入的数据一致,判断大小写.
MM_rsUser.Close
Response.Redirect(MM_redirectLoginSuccess)
else
'如果不一致删除Session变量
Session.Contents.Remove("MM_Username")
Session.Contents.Remove("MM_UserAuthorization")
'重新定义跳转页面!
MM_redirectLoginFailed="index.asp?info=用户名或密码有大小写区分,请重新输入!"
Response.Redirect(MM_redirectLoginFailed)
end if
End If
MM_rsUser.Close
Response.Redirect(MM_redirectLoginFailed)
End If
%>
无标题文档ACTION=""
METHOD="POST" name="form1">
align="center">登录区分大小写
cellspacing="1">
nowrap>User_name:
size="10">
align="right">Pass_word:
type="password" name="Pass_word" value="" size="10">
value="login">
onClick="MM_goToURL('parent','Reg.asp');return
document.MM_returnValue" value="注册">
<> "" then %>
%>
Request.QueryString("info")%>