<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.Security " %>
<html>
  <script language="VB" runat=server>
    Sub Login_Click(Src As Object, E As EventArgs)
        Dim myConnection As OleDbConnection
	Dim myCommand    As OleDbDataAdapter
	Dim ds           As New DataSet
	Dim ConnStr      As String
	Dim SQL          As String
	Dim dv as DataView
	'ConnStr = "DRIVER={Microsoft Access Driver (*.mdb)}; " & _ 
	' "DBQ=" & Server.MapPath("security.mdb")
         ConnStr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("security.mdb") 

        
        myConnection = New OleDbConnection(ConnStr)
        '设置DataSetCommand
        SQL = "select * from passwords"
        myCommand = New OleDbDataAdapter(SQL, myConnection)
        '使用Fill方法填充dataset
         myCommand.Fill(ds, "passwords")
	dv = new DataView(ds.Tables("passwords"))
	dv.Sort = "UserName"
	dv.RowFilter = "UserName = '" + UserName.Value + "' and password = '" + UserPass.Value +"'"
        if dv.count >=1 then
        	'CookieAuthentication.RedirectFromLoginPage(UserName.Value, PersistCookie.Checked)
     		 FormsAuthentication.RedirectFromLoginPage(UserName.Value, PersistCookie.Checked)
     	Else
               Msg.Text = "对不起，用户名或密码错误：请重新登录"
        End if
    End Sub  
  </script>
  <body>
    <form runat=server>
      <h3><font face="Verdana">登录页面</font></h3>
      <table>
        <tr>
          <td>用户名:</td>
          <td><input id="UserName" type="text" runat=server/></td>
          <td><ASP:RequiredFieldValidator ControlToValidate="UserName" Display="Static" ErrorMessage="*" runat=server/></td>
        </tr>
        <tr>	
          <td>密码:</td>
          <td><input id="UserPass" type=password runat=server/></td>
          <td><ASP:RequiredFieldValidator ControlToValidate="UserPass" Display="Static" ErrorMessage="*" runat=server/></td>
        </tr>
        <tr>
          <td>允许 Cookie:</td>
          <td><ASP:CheckBox id=PersistCookie runat="server" /> </td>
          <td></td>
        </tr>
      </table>
      <asp:button text="登录" OnClick="Login_Click" runat=server/>
      <p>
      <asp:Label id="Msg" ForeColor="red" Font-Name="Verdana" Font-Size="10" runat=server />
    </form>
  </body>
</html>
