Hi wyldheinus,
I have created a sample which full fill your requirement you need to modify the code according to your need.
Refer below sample code.
SQL
CREATE TABLE [Users](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](500) NOT NULL,
[Email] [nvarchar](500) NULL,
[UserName] [nvarchar](200) NULL,
[Password] [nvarchar](500) NOT NULL,
[ImageName] [nvarchar](505) NULL)
INSERT [Users] VALUES (N'John Hammond', N'John@gmail.com', N'John1', N'John@356', N'John')
INSERT [Users] VALUES (N'Suzanne', N'Suzanne@gmail.com', N'Suzanne@2', N'Suzanne@125', N'Suzanne')
INSERT [Users] VALUES (N'Robert Schidner', N'Robert@gmail.com', N'Rob@564', N'Rob@1478', N'Robert')
INSERT [Users] VALUES (N'Mathews', N'Mathews@gmail.com', N'Mathews@415', N'Math@758', N'Mathews')
INSERT [Users] VALUES (N'Luke', N'Luke@gmail.com', N'Luke123', N'Luke@369', N'Luke')
INSERT [Users] VALUES (N'Lokesh', N'Lokesh@gmail.com', N'Lokesh785', N'Lok@0231', N'Lokesh')
INSERT [Users] VALUES (N'Ronny', N'Ronny@gmail.com', N'Ronny2451', N'Ron3654', N'Ronny')
Login.aspx
<div>
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
</asp:Login>
</div>
Login.aspx.cs
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT UserName FROM Users WHERE UserName = @Username AND Password = @Password", con);
cmd.Parameters.AddWithValue("@Username", Login1.UserName);
cmd.Parameters.AddWithValue("@Password", Login1.Password);
string userName = cmd.ExecuteScalar().ToString();
Session["UserName"] = userName;
con.Close();
if (!string.IsNullOrEmpty(userName))
{
Response.Redirect("Default.aspx");
}
}
Login.aspx.vb
Protected Sub Login1_Authenticate(sender As Object, e As AuthenticateEventArgs)
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim con As New SqlConnection(constr)
con.Open()
Dim cmd As New SqlCommand("SELECT UserName FROM Users WHERE UserName = @Username AND Password = @Password", con)
cmd.Parameters.AddWithValue("@Username", Login1.UserName)
cmd.Parameters.AddWithValue("@Password", Login1.Password)
Dim userName As String = cmd.ExecuteScalar().ToString()
Session("UserName") = userName
con.Close()
If Not String.IsNullOrEmpty(userName) Then
Response.Redirect("Default.aspx")
End If
End Sub
Default.aspx
<div>
<asp:LoginView ID="LoginView1" Visible="false" runat="server">
<LoggedInTemplate>
<asp:Label ID="lblUserName" runat="server" />
</LoggedInTemplate>
</asp:LoginView>
</div>
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["UserName"] != null)
{
if (Session["UserName"].ToString().ToUpper() == "John1".ToUpper())
{
LoginView1.Visible = true;
(LoginView1.FindControl("lblUserName") as Label).Text = Session["UserName"].ToString();
}
}
}
}
Default.aspx.vb
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
If Session("UserName") IsNot Nothing Then
If Session("UserName").ToString().ToUpper() = "John1".ToUpper() Then
LoginView1.Visible = True
TryCast(LoginView1.FindControl("lblUserName"), Label).Text = Session("UserName").ToString()
End If
End If
End If
End Sub