login page

Posted by Srinu0411 under ASP.NET AJAX on 11/25/2009 | Views : 2571 | Status : [Member] | Replies : 5
my question is create login page.
in my datyabase i have username and password fields.
in login form i have two textboxs txtun and txtpwd and button
now i want to redirect to another page if correct username,password is given or it have to show msg incorrect password

i wrote some extent afterwards iam not getting

con=new SqlConnection("");
con.Open();
cmd=new SqlCommand("select username='" + TextBox1.Text + "',password='" + TextBox2.Text + "' from login",con);
dr=cmd.ExecuteReader();
dr.Read(
con.Close();

kaja srinivas


Responses

Posted by: Abhijit Jana on: 11/25/2009 [Member] [MVP] Bronze

Up
0
Down
Here is the code that you have written
con=new SqlConnection("");

con.Open();
cmd=new SqlCommand("select username='" + TextBox1.Text + "',password='" + TextBox2.Text + "' from login",con);
dr=cmd.ExecuteReader();
dr.Read(
con.Close();

First of all I would like to say, this code is very bad practice. This code may cause of SQL Injection. Always use parametrized query or SP in such case.
You can write one SP which take user name and password as argument and return true if it matched or else it will return false. Based on the return value redirect user to different pages.

Let me know if you need any more help.





Cheers !
Abhijit

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

Posted by: Abhijit Jana on: 11/25/2009 [Member] [MVP] Bronze

Up
0
Down
Here is few Link for your Reference :
http://www.codeproject.com/KB/aspnet/useraccountlogin.aspx


Cheers !
Abhijit

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

Posted by: Srinu0411 on: 11/25/2009 [Member] Starter

Up
0
Down
yes i want code using stored procedure

kaja srinivas

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

Posted by: Abhijit Jana on: 11/25/2009 [Member] [MVP] Bronze

Up
0
Down
Have a look into this thread, it may help you.
http://forums.asp.net/t/1328821.aspx

Let me know if it resolve your issue or not . If not I can again help you, but I want to write you the code, which will build up your confidence,


Cheers !
Abhijit

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

Posted by: Srinu0411 on: 11/25/2009 [Member] Starter

Up
0
Down
iwant to know without stored procedure

iwant to know what to write after cmd.executereader
if uname and password is correct it should go to another page.

i want code part

kaja srinivas

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

Login to post response