N
nasirmajor
dear all,
a simple quetion from still a bigginer in asp.net
i have a simple webpage with username and password which is linked with
database. now when user gives
his username and password and if information is right he does move to
the required webpage. but i want
the session to start with his successful login. how to store his id in
session and start and end it when
logout is clicked.
please any small code sample that can help me.or any good relevent
article to this quetion.
thankyou in advance
my aspx file code is as follows:-
<script runat="server">
SqlConnection objconn=new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data Source=localhost;Integrated
Security=SSPI;");
SqlDataReader objDR;
bool CheckCredentials(string identity2, string Password)
{
objconn.Open();
SqlCommand objcmd=new SqlCommand("SELECT username2,password2
from tbl_login where username2=@username2",objconn);
objcmd.Parameters.Add(new SqlParameter("@username2",
SqlDbType.VarChar, 50));
objcmd.Parameters["@username2"].Value = TextBox1.Text;
objDR = objcmd.ExecuteReader();
if (!objDR.Read())
{
return false;
}
else
{
string strstoredpassword=(string)objDR["password2"];
string strgivenpassword=TextBox2.Text;
return strstoredpassword==strgivenpassword;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckCredentials(TextBox1.Text, TextBox2.Text) == true)
{
string url = "cpanelhome.aspx";
Response.Redirect(url);
}
else
{
Label1.Text = "You entered the wrong credentials!";
}
}
</script>
textbox1 is for username
textbox2 is for password
which works correctly. i want session addition in this code.
thankyou again in advance.
a simple quetion from still a bigginer in asp.net
i have a simple webpage with username and password which is linked with
database. now when user gives
his username and password and if information is right he does move to
the required webpage. but i want
the session to start with his successful login. how to store his id in
session and start and end it when
logout is clicked.
please any small code sample that can help me.or any good relevent
article to this quetion.
thankyou in advance
my aspx file code is as follows:-
<script runat="server">
SqlConnection objconn=new SqlConnection("user
id=sa;password=;Initial Catalog=jobsdb;Data Source=localhost;Integrated
Security=SSPI;");
SqlDataReader objDR;
bool CheckCredentials(string identity2, string Password)
{
objconn.Open();
SqlCommand objcmd=new SqlCommand("SELECT username2,password2
from tbl_login where username2=@username2",objconn);
objcmd.Parameters.Add(new SqlParameter("@username2",
SqlDbType.VarChar, 50));
objcmd.Parameters["@username2"].Value = TextBox1.Text;
objDR = objcmd.ExecuteReader();
if (!objDR.Read())
{
return false;
}
else
{
string strstoredpassword=(string)objDR["password2"];
string strgivenpassword=TextBox2.Text;
return strstoredpassword==strgivenpassword;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckCredentials(TextBox1.Text, TextBox2.Text) == true)
{
string url = "cpanelhome.aspx";
Response.Redirect(url);
}
else
{
Label1.Text = "You entered the wrong credentials!";
}
}
</script>
textbox1 is for username
textbox2 is for password
which works correctly. i want session addition in this code.
thankyou again in advance.