文章編號: 321503 - 上次校閱: 2006年12月18日 - 版次: 3.1

如何輸入使用者名稱及密碼在 FrontPage 2000 中的使用資料庫

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
本文章的有 Microsoft FrontPage 2002] 版本請參閱 321439? (http://support.microsoft.com/kb/321439/ )

在此頁中

全部展開 | 全部摺疊

結論

本文將逐步說明如何使用 Microsoft FrontPage 2000]、 [動態伺服器網頁 (ASP)] 及 [Microsoft Access 資料庫中建立簡單的檔案安全性解決方案。

重要注意事項

  • 本文中的範例程式碼不被設計為用來取代 FrontPage 內建的安全性功能。範例是設計用來提供簡單的安全性機制只針對的瀏覽至您的網站的使用者。像這類 FrontPage 2000 安全性並不整合與使用者名稱及密碼新增至 Microsoft Access 資料庫。
  • 使用者名稱和在輸入的密碼會以純文字在網際網路上傳輸。更高安全性的 Microsoft 建議您使用 Web 伺服器,可以使用安全通訊端層 (SSL) 加密。如需詳細資訊,請詢問網站管理員或網際網路服務提供者 (ISP)。

步驟 1-取得就緒要在 FrontPage 2000 中使用 ASP 功能

您可以在 FrontPage 2000 中使用 ASP 功能之前,您必須安裝下列 「 Microsoft 知識庫 」 文件中所列的元件:
312638? (http://support.microsoft.com/kb/312638/ ) 項目所需在 FrontPage 2000 中使用動態伺服器網頁 (ASP) 的描述

步驟 2-在 FrontPage 2000 建立新的網頁

附註如需此程式範例才能正常運作中,您必須確定 Web name 是登入,它是關閉您的網站的根目錄的子 Web。
  1. 在 [檔案] 功能表上按一下 [新增],然後按一下 [Web]。
  2. 在範本清單中,按一下 [空白網頁]。
  3. 使用下列語法來指定您伺服器上的 Web 位置
    your server /logon/ http://
    其中 your server 是您的 ASP 啟用 Web 伺服器的名稱。

  4. 按一下 [確定]

步驟 3-使用 Microsoft Access 中建立資料庫

  1. 啟動 Microsoft Access。
  2. 按一下 [檔案] 功能表 新增]
  3. 在選擇清單中按一下 [空白資料庫]。
  4. 命名檔案 logon.mdb,然後將它儲存到您的桌面。
  5. 在 [資料表] 區段中,按一下 [新增]。
  6. 按一下 [設計檢視],然後再按一下 [確定]
  7. 建立兩個欄位:
    1. 欄位名稱 輸入 UID。如 資料類型 按一下 [文字,] 然後按一下 [主索引鍵]。
    2. 欄位名稱 輸入 PWD資料類型 按一下 [文字]。
  8. 在 [檔案] 功能表上按一下 [儲存]。命名表格 tblUsers,然後按一下 [確定]
  9. 按一下 [檢視] 功能表 資料工作表檢視
  10. 在 [UID] 欄中,鍵入 testuser。在 [PWD] 欄中,鍵入 密碼
  11. 在 [檔案] 功能表上, 按一下 [關閉]。
  12. 請結束部份的 Microsoft Access。
附註基於安全性考量密碼是限於混合大寫字母、 小寫字母及數字。

步驟 4-匯入 Microsoft Access 資料庫

  1. 按一下 [檔案] 功能表 匯入
  2. 按一下 [新增檔案]。
  3. 在 [查詢] 清單中,按一下您的桌面。
  4. 按一下您在 Step 3logon.mdb 檔案,然後按一下 [開啟舊檔]。
  5. 按一下 [修改]。
  6. _private/logon.mdb,變更 URL,然後按一下 [確定]
  7. 按一下 [確定],匯入檔案。
  8. 如果系統提示您新增資料庫連線,請按一下 []。

步驟 5-建立 ASP 網頁

您必須建立數個檔案來使用這個範例。建立您的網站]、 [unsecure page] 及 [secure page 進行測試,一個 home page 的第一次,然後 logon Web pagelogon include file

步驟 5a-建立首頁

此頁面來當做您的網站預設的網頁,包含 unsecure page 和稍後建立 secure page 的連結。
  1. FrontPage] 工具列上按一下 [新增頁面]。
  2. 切換至 HTML 檢視,然後再刪除所有現有的 HTML 程式碼。
  3. 輸入或貼上下列程式碼插入網頁:
    <% @language="vbscript" %>
    <html>
    <head><title>Home Page</title></head>
    <body>
    <h3>Home Page</h3>
    <p>You are logged on as: 
    <%
      If Len(Session("UID")) = 0 Then
        Response.Write "<b>You are not logged on.</b>"
      Else
        Response.Write "<b>" & Session("UID") & "</b>"
      End If
    %>
    </p>
    <ul>
    <li><a href="secure.asp">Secure Page</a></li>
    <li><a href="unsecure.asp">Unsecure Page</a></li>
    </ul>
    </body>
    </html>
    					
  4. 將頁面儲存為 default.asp 您登入 Web 的根資料夾中。
  5. 按一下 [檔案] 功能表上的 [關閉] 關閉 [頁]。

步驟 5b]-建立不安全的頁面

此頁面是基本的 ASP 網頁,任何人都可以瀏覽。
  1. FrontPage] 工具列上按一下 [新增頁面]。
  2. 切換至 HTML 檢視,然後再刪除所有現有的 HTML 程式碼。
  3. 輸入或貼上下列程式碼插入網頁:
    <% @language="vbscript" %>
    <html>
    <head><title>Unsecure Page</title></head>
    <body>
    <h3>Unsecure Page</h3>
    <p>You are logged on as: 
    <%
      If Len(Session("UID")) = 0 Then
        Response.Write "<b>You are not logged on.</b>"
      Else
        Response.Write "<b>" & Session("UID") & "</b>"
      End If
    %>
    </p>
    <p><a href="default.asp">Back to default</a></p>
    </body>
    </html>
    					
  4. 將頁面儲存為您的登入 Web 的根資料夾中的 unsecure.asp"。
  5. 按一下 [檔案] 功能表上的 [關閉] 關閉 [頁]。

步驟 5 c-建立安全的網頁

這個步驟中是為您在 Step 5b 中, 建立的非安全網頁相同,只不過新增下行程式碼在頁面頂端附近的:
<!--#include virtual="/logon/_private/logon.inc"-->
				
任何 ASP 網頁中加入這一行程式碼讓分頁 「 安全 」 的 Web 網頁。
  1. FrontPage] 工具列上按一下 [新增頁面]。
  2. 切換至 HTML 檢視,然後再刪除所有現有的 HTML 程式碼。
  3. 輸入或貼上下列程式碼插入網頁:
    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->
    <html>
    <head><title>Secure Page</title></head>
    <body>
    <h3>Secure Page</h3>
    <p>You are logged on as: 
    <%
      If Len(Session("UID")) = 0 Then
        Response.Write "<b>You are not logged on.</b>"
      Else
        Response.Write "<b>" & Session("UID") & "</b>"
      End If
    %>
    </p>
    <p><a href="default.asp">Back to default</a></p>
    </body>
    </html>
    					
  4. 將頁面儲存為 secure.asp 您登入 Web 的根資料夾中。
  5. 按一下 [檔案] 功能表上的 [關閉] 關閉 [頁]。

步驟 5 d-建立登入頁面

登入頁面的設計被為了類似標準的 Windows 登入對話方塊。嘗試存取 secure page 的使用者會傳送到此頁面以輸入其使用者名稱和密碼。
  1. FrontPage] 工具列上按一下 [新增頁面]。
  2. 切換至 HTML 檢視,然後再刪除所有現有的 HTML 程式碼。
  3. 輸入或貼上下列程式碼插入網頁:
    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->
    <%
      ' Was this page posted to?
      If UCase(Request.ServerVariables("HTTP_METHOD")) = "POST" Then
        ' If so, verify the username/password that was entered.
        If ComparePassword(Request("UID"),Request("PWD")) Then
          ' If comparison was good, store the user name...
          Session("UID") = Request("UID")
          ' ..and redirect back to the original page.
          Response.Redirect Session("REFERRER")
        End If
      End If
    %>
    <html>
    <head><title>Logon Page</title>
    <style>
    body  { font-family: arial, helvetica }
    table { background-color: #cccccc; font-size: 9pt; padding: 3px }
    td    { color: #000000; background-color: #cccccc; border-width: 0px }
    th    { color: #ffffff; background-color: #0000cc; border-width: 0px }
    </style>
    </head>
    <body bgcolor="#000000" text="#ffffff">
    <h3 align="center">&#xa0;</h3>
    <div align="center"><center>
    <form action="<%=LOGON_PAGE%>" method="POST">
    <table border="2" cellpadding="2" cellspacing="2">
      <tr>
        <th colspan="4" align="left">Enter User Name and Password</th>
      </tr>
      <tr>
        <td>&#xa0;</td>
        <td colspan="2" align="left">Please type your user name and password.</td>
        <td>&#xa0;</td>
      </tr>
      <tr>
        <td>&#xa0;</td>
        <td align="left">Site</td>
        <td align="left"><%=Request.ServerVariables("SERVER_NAME")%> &#xa0;</td>
        <td>&#xa0;</td>
      </tr>
      <tr>
        <td>&#xa0;</td>
        <td align="left">User Name</td>
        <td align="left"><input name="UID" type="text" size="20"></td>
        <td>&#xa0;</td>
      </tr>
      <tr>
        <td>&#xa0;</td>
        <td align="left">Password</td>
        <td align="left"><input name="PWD" type="password" size="20"></td>
        <td>&#xa0;</td>
      </tr>
      <tr>
        <td>&#xa0;</td>
        <td colspan="2" align="center"><input type="submit" value="LOGON"></td>
        <td>&#xa0;</td>
      </tr>
    </table>
    </form>
    </center></div>
    </body>
    </html>
    					
  4. 將頁面儲存為 logon.asp 您登入 Web 的根資料夾中。
  5. 按一下 [檔案] 功能表上的 [關閉] 關閉 [頁]。

步驟 5e-建立登入要求包含檔案

此包含檔案提供使用者名稱和密碼功能,而會使用 secure pagelogon page
  1. FrontPage] 工具列上按一下 [新增頁面]。
  2. 切換至 HTML 檢視,然後再刪除所有現有的 HTML 程式碼。
  3. 輸入或貼上下列程式碼插入網頁:
    <%
      ' Do not cache this page.
      Response.CacheControl = "no-cache"
    
      ' Define the name of the users table.
      Const USERS_TABLE  = "tblUsers"
      ' Define the path to the logon page.
      Const LOGON_PAGE   = "/logon/logon.asp"
      ' Define the path to the logon database.
      Const MDB_URL      = "/logon/_private/logon.mdb"
    
      ' Check to see whether you have a current user name.
      If Len(Session("UID")) = 0 Then
        ' Are you currently on the logon page?
        If LCase(LOGON_PAGE) <> LCase(Request.ServerVariables("URL")) Then
          ' If not, set a session variable for the page that made the request...
          Session("REFERRER") = Request.ServerVariables("URL")
          ' ...and redirect to the logon page.
          Response.Redirect LOGON_PAGE
        End If
      End If
    
      ' This function checks for a username/password combination.
      Function ComparePassword(UID,PWD)
        ' Define your variables.
        Dim strSQL, objCN, objRS
        ' Set up your SQL string.
        strSQL = "SELECT * FROM " & USERS_TABLE & _
          " WHERE (UID='" & ParseText(UID) & _
          "' AND PWD='" & ParseText(PWD) & "');"
        ' Create a database connection object.
        Set objCN = Server.CreateObject("ADODB.Connection")
        ' Open the database connection object.
        objCN.Open "driver={Microsoft Access Driver (*.mdb)}; dbq=" & _
          Server.MapPath(MDB_URL) & "; uid=admin; pwd="
        ' Run the database query.
        Set objRS = objCN.Execute(strSQL)
        ' Set the status to true/false for the database lookup.
        ComparePassword = Not(objRS.EOF)
        ' Close your database objects.
        Set objRS = Nothing
        Set objCN = Nothing
      End Function
    
      ' This function restricts text to alpha-numeric data only.
      Function ParseText(TXT)
        Dim intPos, strText, intText
        For intPos = 1 TO Len(TXT)
          intText = Asc(Mid(TXT,intPos,1))
          If (intText > 47 And intText < 58) Or _
             (intText > 64 And intText < 91) Or _
             (intText > 96 And intText < 123) Then
              strText = strText & Mid(TXT,intPos,1)
          End if
        Next
        ParseText = strText
      End Function
    %>
  4. 將頁面儲存為 logon.inc 您登入網頁的 [_private] 資料夾中。
  5. 按一下 [檔案] 功能表上的 [關閉] 關閉 [頁]。

步驟 6-測試登入網頁

  1. 在 FrontPage 資料夾清單] 中,按一下 default.asp。在 [FrontPage] 工具列上按一下 [在瀏覽器中的預覽]。
  2. 現在,您的瀏覽器載入範例首頁,並顯示您並未登入。
  3. 按一下不安全的頁面連結。網頁載入並顯示您並未登入。按一下 [回到預設網頁連結。
  4. 按一下連結以安全的網頁。載入登入頁面而非安全網頁。
  5. 輸入 testuser 的使用者名稱、 輸入該密碼的 密碼,然後按一下 [登入
  6. 安全的網頁會出現,並顯示您登入為 testuser。按一下 [回到預設網頁連結。
  7. 範例首頁載入,並顯示您正在登入為 testuser。
  8. 按一下不安全的頁面連結。網頁載入並顯示您所登入為 testuser。

自訂登入範例

您可以下列方式自訂登入範例:
  • 新增使用者名稱和密碼: 您可以開啟資料庫,方法是按兩下透過 FrontPage 然後新增使用者至 tblUsers 資料表。
  • 保護其他 Web 網頁安全: 到安全的另一個網頁在您的網頁,您必須將檔案儲存的 ASP 副檔名的檔案,例如 mypage.asp,然後將下列兩行新增到檔案頂端:
    <% @language="vbscript" %>
    <!--#include virtual="/logon/_private/logon.inc"-->
    						
    的第一行您指令碼語言指定 [您正使用 Microsoft Visual Basic 指令碼版 (VBScript) 以及第二行包括使用者名稱和密碼功能,從 logon include file 先前建立之。

?考

如更多有關資料庫和安全性與整合動態伺服器網頁 (ASP) 的資訊,按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中 「 文件:
299987? (http://support.microsoft.com/kb/299987/ ) 如何使用來實作 ASP 安全性的資料庫和 ASP 工作階段
300382? (http://support.microsoft.com/kb/300382/ ) 如何從 ASP 網頁建立資料庫連接

這篇文章中的資訊適用於:
  • Microsoft FrontPage 2000 Standard Edition
關鍵字:?
kbmt kbhowto kbhowtomaster KB321503 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:321503? (http://support.microsoft.com/kb/321503/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。