473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

session state with user login2

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.

Jun 29 '06 #1
1 1184
Hi
When the user is successfully authenticated store in a session variable
session("userid") = userid

When the user logs out abandon the session. But, you need to check for the
session value on every page load. You can use forms authentication instead.
Or the new login controls of version 2
--
---------------------------
Thanks,
Ibrahim
If you find this post useful, please click 'yes'
"na********@yahoo.com" wrote:
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.

Jun 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chip | last post by:
I am trying to get sessions to work on a log in screen to give certain users access to certain pages/directories. The problem is that when the login button is pushed (or the enter key pressed) the...
2
by: Rajagopal | last post by:
Hi, I have a application which i would require to use for two different set of users. For one set of users i need to set the session timeout as 60 minutes, which i can configure using...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
2
by: Rajagopal | last post by:
Hi, I have a application which i would require to use for two different set of users. For one set of users i need to set the session timeout as 60 minutes, which i can configure using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.