Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Demo of Login Control

Source Code
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="login.aspx.vb"
Inherits="p2q3.login" %>

<!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0


Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99"
BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt"
Height="145px" Width="301px">
<HyperLinkStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<InstructionTextStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<FailureTextStyle HorizontalAlign="Center" />
<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
<br />
</form>
</body>
</html>

Vb Code
Imports System.Data
Imports System.Data.SqlClient

Public Class login


Inherits System.Web.UI.Page
Dim str As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\
admin\Documents\india.mdf;Integrated Security=True;Connect Timeout=30;User
Instance=True")
Private Property Query As String

Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As


System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate
Dim query As String
Dim cn As New SqlConnection(str, SqlConnection)
Dim cmd As New SqlCommand
Dim dr As SqlDataReader ' To hold/store database records
cn.Open()
query = "Select UsrName from UserMst where UsrName='" & Login1.UserName & "'
and Passwd='" & Login1.Password & "'"
cmd.CommandText = Query
cmd.Connection = cn
dr = cmd.ExecuteReader()
If dr.HasRows = False Then
e.Authenticated = False
Else
e.Authenticated = True
Session("user") = Login1.UserName
Response.Redirect("Default2.aspx")
End If
End Sub

Private Function SqlConnection() As String


Throw New NotImplementedException
End Function

Private Shared Function UserName() As String


Throw New NotImplementedException
End Function

Private Shared Function Password() As String


Throw New NotImplementedException
End Function

End Class

You might also like