using database for login authentication for session??

Posted by Shailesh21235 under ASP.NET on 6/18/2012 | Points: 10 | Views : 1533 | Status : [Member] | Replies : 1
protected void btnLogin_Click(object sender, EventArgs e)
{
if (Page.IsValid)
if (txtUser.Text == "ram")
{
if (txtPassword.Text == "12")
{
Session["User"] = "ram";
Response.Redirect("~/Default.aspx");
}
else
{
Response.Write("Invalid Password");
txtPassword.Text = string.Empty;
txtPassword.Focus();
}
}
else
{
Response.Write("Invalid User Name");
txtUser.Text = string.Empty;
txtUser.Focus();
}
}
here for login i have manually filled the datas in the textboxes for comparing??
how can i use the database for the login authentication with session in the login page?? instead of assiging value here how can i access the values from database??




Responses

Posted by: Ajay.Kalol on: 6/19/2012 [Member] Starter | Points: 25

Up
0
Down
Dim cn As New SqlConnection("Connection String")

Dim objAdapter As SqlDataAdapter
Dim DT As New DataTable
objAdapter = New SqlDataAdapter("select * from LoginMaster where UserName = '"+txtUserName.Text+"' AND Password = '"+txtPassword.text+"' ", cn)
objAdapter.Fill(DT)

if(DT.rows.count > 0)
{
response.redirect("~/Home.aspx")
}
else
{
response.write("Invalid Login Detail")
}


Ajay
ajaypatelfromsanthal.blogspot.in

Shailesh21235, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response