473,403 Members | 2,270 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,403 software developers and data experts.

Session problems with LOGIN/Validating

I have a problem with the code below:-
When i use a username for example dog for the first time it works but later
when i use cat for example it keeps showing
Hello:- Dog..
It keeps DOG in the session for long.

But i want to get the USERNAME from the datbase and display it
so it catches only the username from the DB only..

I think 'm not placing the "Session["name"] = username.Text; "
CAN ANYBODY ADVICE WHERE I SHOULD PUT THE "SESSION"

Help if u can..PLease..look at the code properly
Thx

void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE
username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext,
false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
Session["name"] = username.Text;
cn.Close();
}

Nov 18 '05 #1
3 1239
if(dr["Password"].ToString() == Password.Text)
Session["name"] = username.Text;
// every time a new user is successfully matched, it is at that point
// that you want to store their entered username in Session.
"Patrick.O.Ige" <pa********@acn.waw.pl> wrote in message
news:O8****************@TK2MSFTNGP10.phx.gbl...
I have a problem with the code below:-
When i use a username for example dog for the first time it works but later when i use cat for example it keeps showing
Hello:- Dog..
It keeps DOG in the session for long.

But i want to get the USERNAME from the datbase and display it
so it catches only the username from the DB only..

I think 'm not placing the "Session["name"] = username.Text; "
CAN ANYBODY ADVICE WHERE I SHOULD PUT THE "SESSION"

Help if u can..PLease..look at the code properly
Thx

void Login_Click(Object sender, EventArgs e)
{

SqlDataReader dr;

SqlConnection cn = new SqlConnection("Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI;");

cn.Open();

SqlCommand cmdQuestion = new SqlCommand("SELECT Password FROM Users WHERE username = '" + username.Text + "'", cn);

dr=cmdQuestion.ExecuteReader();

if(dr.Read())

if(dr["Password"].ToString() == Password.Text)
// CookieAuthentication.RedirectFromLoginPage(Email.T ext,
false);
Response.Redirect("testlabel.aspx");

else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
Session["name"] = username.Text;
cn.Close();
}

Nov 18 '05 #2
Thx for the advice..
but when i do:-it says error:-"Invalid attempt to read when no data is
present."
Can you help me with the code!!
Thx
if(dr["Password"].ToString() == Password.Text) {
Session["name"] = username.Text; }
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");
// else Msg.Text = "Invalid password.";

if(dr.Read()) {
//else
}
Msg.Text = "Email address not found.";

//Session["name"] = username.Text;
//Session["name"] = dr["username.Text"].ToString();
//Session.Terminate();
cn.Close();
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Hi Peter..
Well I did this(And its WORKING !!!! ):-
Thx mo!!U are the best in the FORUM!!

if(dr.Read()) if(dr["Password"].ToString() == Password.Text)
{
Session["name"] = username.Text;
// CookieAuthentication.RedirectFromLoginPage(Email.T ext, false);
Response.Redirect("testlabel.aspx");
}
else
Msg.Text = "Invalid password.";
else
Msg.Text = "Email address not found.";
cn.Close();


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #4

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

Similar topics

3
by: nao921 | last post by:
Hi everyone, I am currently involved in a project that involves a windows client program written in delphi and a web application written in php. I have made several php pages for the delphi...
6
by: John | last post by:
Hi. I am having a few header problems at the moment with a login page. I don't have my headers at the top of the page where I've learned I need to have them. However, I also know I'm supposed...
8
by: P. Glassel | last post by:
I'm having problems getting session timeouts to change programmaticlaly under IIS6.0. This is unchanged code that ran as expected under IIS5.0. Anyone else run into this problem? Thx.
0
by: Knowledge_Sponge | last post by:
I have an ASP page that sends a location variabe to the database and retrieves the appropriate corresponding data. I would like to add a simple password to open this page. The page is accessed by...
0
by: Tony | last post by:
We are a software company that builds an ASP.Net web application which implements cookieless sessionState with SQLServer- the session is stored in the url. Our ASPState database has been built...
3
by: headware | last post by:
I have an issue that I've been encountering in an ASP application I'm working on. Most of the application is written in ASP, but there is one page written in ASP.NET. The ASP.NET page needs to have...
4
by: Patrick.O.Ige | last post by:
I have a code below.(It validates against a SQL DB(login page).thats is giving me an error! When i try to use :- Session = dr.ToString(); To catch the username so as to redirect the user logged in...
43
by: davidkoree | last post by:
I mean not about cookie. Does it have something to do with operating system or browser plugin? I appreciate any help.
13
by: Samir Chouaieb | last post by:
Hello, I am trying to find a solution to a login mechanism for different domains on different servers with PHP5. I have one main domain with the user data and several other domains that need...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.