Hi all,
I created a sample web application. in this I have sign up and login pages.
The data I enterd in signup page is stored in db.Now when I enter user name and password these data is checked with the db values. If these username and password values are in db then i redirected to another page . otherwise An error message should be displyed. I written code but it is not working.
Here is my code.
[CODE=cpp]protected void Button2_Click(o bject sender, EventArgs e)
{
string uname; string pword;
uname = TextBox1.Text;
pword = TextBox2.Text;
SqlConnection myConnection = new SqlConnection(" Server=Server2; Database=projec t;Trusted_Conne ction=yes");
String selectcmd = "select username,passwo rd from signup where username='" + uname + "' && password = '" + pword + "' ";
SqlCommand myCommand = new SqlCommand(sele ctcmd, myConnection);
myCommand.Conne ction.Open();
int returnRows = myCommand.Execu teNonQuery();
myCommand.Conne ction.Close();
if (returnRows ==1)
{
Response.Write( "redirect.aspx" );
}
else
{
Label1.Text = "You enterd incorrect username or password";
}
}[/CODE]
Please suggest if any changes in this code or suggest me another way.
Thanks.
I created a sample web application. in this I have sign up and login pages.
The data I enterd in signup page is stored in db.Now when I enter user name and password these data is checked with the db values. If these username and password values are in db then i redirected to another page . otherwise An error message should be displyed. I written code but it is not working.
Here is my code.
[CODE=cpp]protected void Button2_Click(o bject sender, EventArgs e)
{
string uname; string pword;
uname = TextBox1.Text;
pword = TextBox2.Text;
SqlConnection myConnection = new SqlConnection(" Server=Server2; Database=projec t;Trusted_Conne ction=yes");
String selectcmd = "select username,passwo rd from signup where username='" + uname + "' && password = '" + pword + "' ";
SqlCommand myCommand = new SqlCommand(sele ctcmd, myConnection);
myCommand.Conne ction.Open();
int returnRows = myCommand.Execu teNonQuery();
myCommand.Conne ction.Close();
if (returnRows ==1)
{
Response.Write( "redirect.aspx" );
}
else
{
Label1.Text = "You enterd incorrect username or password";
}
}[/CODE]
Please suggest if any changes in this code or suggest me another way.
Thanks.
Comment