这里只贴了代码部分,网页就不贴了
Imports System.Web.Security
Imports System.Data.OleDb
Public Class login
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents txtAcc As System.Web.UI.WebControls.TextBox
Protected WithEvents txtPwd As System.Web.UI.WebControls.TextBox
Protected WithEvents btnLog As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents chkAdmin As System.Web.UI.WebControls.CheckBox
Protected WithEvents RequiredFieldValidatorAcc As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidatorPwd As System.Web.UI.WebControls.RequiredFieldValidator
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If User.Identity.IsAuthenticated Then
Response.Redirect("logoff.aspx")
End If
End Sub
Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
Dim strUsername As String
Dim strPassword As String
Dim strAuthor As String
strUsername = txtAcc.Text.ToUpper
strPassword = txtPwd.Text
If chkAdmin.Checked = False Then
strAuthor = "Student"
Else
strAuthor = "Admin"
End If
If Authenticate(strUsername, strPassword, strAuthor) Then
FormsAuthentication.RedirectFromLoginPage(strUsername, False)
End If
End Sub
Private Function Authenticate(ByVal strUsername As String, ByVal strPassword As String, ByVal strAuthor As String) As Boolean
Dim strQuery As String
Dim blResult As Boolean
strQuery = "SELECT * FROM Yonghu WHERE Kaohao='" & strUsername & "' AND Mima='" & strPassword & "' AND Quanxian='" & strAuthor & "'"
Dim conExam As OleDbConnection
Dim cmdSelect As OleDbCommand
blResult = False
conExam = New OleDbConnection(strConn)
cmdSelect = New OleDbCommand(strQuery, conExam)
Try
conExam.Open()
blResult = cmdSelect.ExecuteReader.Read
Finally
conExam.Close()
End Try
Return blResult
End Function
End Class
<!--
The LoginBtn_Click event handler uses the Authenticate method to check the
user name and password entered by the user against the credentials stored
in the credential data store. If the username and password are correct as
verified by the authentication event handler function, the RedirectFromLoginPage
method transfers the user back to the protected resource. The
FormsAuthenticationEventHandler Delegate function is not included in this example.
-->
<%@ Page Language="VB" AutoEventWireup="true" %>
<html>
<head>
<script runat="server">
Sub LoginBtn_Click(sender as Object, e as EventArgs)
If Page.IsValid Then
' Call the authentication event handler delegate (not included in this example).
If FormsAuthentication.Authenticate(UserName.Text, UserPass.Text) Then
' Return to the originally requested URL.
FormsAuthentication.RedirectFromLoginPage(UserName.Text, Remember.Checked)
Else
Msg.Text = "Invalid Credentials: Please try again"
End If
End If
End Sub
</script>
</head>
<body>
<!--
This form gets the user name and password from the user.
The LoginBtn_Click event handler is called when the
Login button is clicked to authenticate the user.
-->
<form runat="server">
<h2>Login Page</h2>
<hr size="1" />
<table>
<tbody>
<tr>
<td>Username:</td>
<td><asp:TextBox id="UserName" runat="server"></asp:TextBox></td>
<td><asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="UserName"
Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td>Password:</td>
<td><asp:TextBox id="UserPass" runat="server" TextMode="Password"></asp:TextBox></td>
<td><asp:RequiredFieldValidator id="RequiredFieldValidator2" runat="server" ControlToValidate="UserPass"
Display="Static" ErrorMessage="*"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td colspan="3"> <asp:CheckBox id="Remember" runat="server"></asp:CheckBox>Remember credentials?</td>
</tr>
</tbody>
</table>
<asp:button id="LoginBtn" onclick="LoginBtn_Click" runat="server" text="Login"></asp:button>
<p><asp:Label id="Msg" runat="server" ForeColor="red"></asp:Label></p>
</form>
</body>
</html>