OR
User authenticate in asp.net
-->User authenticate required when Unauthorized user not access
some pages in your website
--> Table name tbl_Student
--> field (Id,Name,Address,.....User_Id,Password)
-->Add following namespace in your code behind file
------------------------------------------------------------------------------------------------
using System.Data;
using System.Data.SqlClient;
--> And then create following object above page load event
------------------------------------------------------------------------------------------------
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
--> Follwing code paste in your log_in button on click event
------------------------------------------------------------------------------------------------
cmd = new SqlCommand("select * from tbl_Student where
User_Id=' "+txtUser.Text+" ' and Password=' "+txtPwd.Text+" ' ", cn);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
//when user id and password match then
string Id=ds.Tables[0].Rows[0][0].ToString();
Session["UserSession"]=Id;
//Create session and use this session in entire application
Response.Redirect("User/Home.aspx");
//Successfully log in
}
else
{
//when user id and password does not match then
Label1.Text="User name and Password does not match";
}
User authenticate in asp.net
-->User authenticate required when Unauthorized user not access
some pages in your website
--> Table name tbl_Student
--> field (Id,Name,Address,.....User_Id,Password)
-->Add following namespace in your code behind file
------------------------------------------------------------------------------------------------
using System.Data;
using System.Data.SqlClient;
--> And then create following object above page load event
------------------------------------------------------------------------------------------------
SqlConnection cn;
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
--> Follwing code paste in your log_in button on click event
------------------------------------------------------------------------------------------------
cmd = new SqlCommand("select * from tbl_Student where
User_Id=' "+txtUser.Text+" ' and Password=' "+txtPwd.Text+" ' ", cn);
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
if(ds.Tables[0].Rows.Count>0)
{
//when user id and password match then
string Id=ds.Tables[0].Rows[0][0].ToString();
Session["UserSession"]=Id;
//Create session and use this session in entire application
Response.Redirect("User/Home.aspx");
//Successfully log in
}
else
{
//when user id and password does not match then
Label1.Text="User name and Password does not match";
}
No comments:
Post a Comment