ASP 101 - Active Server Pages 101 login_db.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="VB" runat="server">
	Sub btnLogin_OnClick(Src As Object, E As EventArgs)
		Dim myConnection  As OleDbConnection
		Dim myCommand     As OleDbCommand
		Dim intUserCount  As Integer
		Dim strSQL        As String
		strSQL = "SELECT COUNT(*) FROM tblLoginInfo " _
			& "WHERE username='" & Replace(txtUsername.Text, "'", "''") & "' " _
			& "AND password='" & Replace(txtPassword.Text, "'", "''") & "';"
		myConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
			& "Data Source=" & Server.MapPath("login.mdb") & ";")
		myCommand = New OleDbCommand(strSQL, myConnection)
		myConnection.Open()
		intUserCount = myCommand.ExecuteScalar()
		myConnection.Close()
		'Response.Write(intUserCount)
		If intUserCount > 0 Then
			lblInvalid.Text = ""
			'FormsAuthentication.RedirectFromLoginPage(txtUsername.Text, True)
			FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
	        Response.Redirect("login_db-protected.aspx")
		Else
			lblInvalid.Text = "Sorry... try again..."
		End If
	End Sub
</script>
<html>
<head>
<title>ASP.NET Login (Database-Driven) Sample</title>
</head>
<body>
<h2>Please Login:</h2>
<p>
Hint: Username is "anna", "bob", "chris", or "dave" and Password is "password"
</p>
<p>
<asp:Label id="lblInvalid" runat="server" />
</p>
<form runat="server">
	Username: <asp:TextBox id="txtUsername" runat="server" /><br />
	Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" /><br />
	<br />
	<asp:Button id="btnLogin" runat="server"
		text="Login" OnClick="btnLogin_OnClick"
	/>
</form>
<p>
Here's the page we're protecting:
<a href="login_db-protected.aspx">login_db-protected.aspx</a>.
If you're not logged in, clicking the link will bounce
you right back to this page.
</p>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/login_db_aspx.asp">here</a> to read about and download the source code.
</p>
</body>
</html>