Login form Demo (VB.net) : Log In « Components « ASP.Net





Login form Demo (VB.net)

<%--
Code revised from 

ASP.NET Tips & Techniques (Paperback)
by Greg Buczek 


# Publisher: McGraw-Hill/Osborne Media; 1st edition (May 21, 2002)
# Language: English
# ISBN: 0072225149

--%>   

<%@ Page Language=VB Debug=true %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OLEDB" %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
    Dim DBConn as OleDbConnection
    Dim DBCommand As OleDbDataAdapter
    Dim DSLogin as New DataSet
    DBConn = New OleDbConnection("PROVIDER=" _
        & "Microsoft.Jet.OLEDB.4.0;" _
        & "DATA SOURCE=" _
        & Server.MapPath("LogIn.mdb;"))
    DBCommand = New OleDbDataAdapter _
        ("Select UserID from " _
        & "Users Where " _
        & "UserName = '" & txtUserName.Text _
        & "' and Password = '" & txtPassword.Text _
        & "'", DBConn) 
    DBCommand.Fill(DSLogin, _
        "UserInfo")
    If DSLogin.Tables("UserInfo"). _
        Rows.Count = 0 Then
        lblMessage.Text = "The user name and password " _
            & "were not found. Please try again."
    Else
        Session("UserID") = DSLogin.Tables("UserInfo"). _
            Rows(0).Item("UserID")
        Session("UserName") = txtUserName.Text
        Response.Redirect("./welcome.aspx")
    End If
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Log In Page</TITLE>
</HEAD>
<form runat="server">
<asp:Label 
    id="lblMessage" 
    Font-Size="12pt"
    Font-Name="Tahoma"
    runat="server"
    Text="Complete each field to enter the site."
/>
<P></P><Font Face="Tahoma">User Name:</Font><BR>
<asp:TextBox 
    id="txtUserName" 
    Columns="25"
    MaxLength="50"
    runat=server 
/>
<asp:RequiredFieldValidator 
    id="rfvUserName"
    ControlToValidate="txtUserName"
    Display="Dynamic"
    Font-Name="Tahoma"
    Font-Size="10pt"
    runat=server>
    User Name is Required!
</asp:RequiredFieldValidator>
<P></P><Font Face="Tahoma">Password:</Font><BR>
<asp:TextBox 
    id="txtPassword" 
    Columns="25"
    MaxLength="50"
    runat=server 
    TextMode="Password"
/>
<asp:RequiredFieldValidator 
    id="rfvPassword"
    ControlToValidate="txtPassword"
    Display="Dynamic"
    Font-Name="Verdana"
    Font-Size="10pt"
    runat=server>
    Password is Required!
</asp:RequiredFieldValidator><BR><BR>
<asp:button 
    id="butOK"
    text="  OK  "
    OnClick="SubmitBtn_Click" 
    runat="server"
/>
</form>
</BODY>
</HTML>

<%-- Welcome.aspx

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)
    If Len(Session("UserID")) = 0 Then
        Response.Redirect("./login.aspx")
    End If
    lblMessage.Text = "Welcome: " & Session("UserName")
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Welcome Page</TITLE>
</HEAD>
<form runat="server">
<asp:Label 
    id="lblMessage" 
    Font-Size="12pt"
    Font-Name="Tahoma"
    runat="server"
/>
</form>
</BODY>
</HTML>

--%>
           
       










LogIn.zip( 8 k)

Related examples in the same category