Asp .Net : Issue with logging into application

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shilpareddy2787
    New Member
    • Nov 2007
    • 11

    Asp .Net : Issue with logging into application

    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.
    Last edited by Shashi Sadasivan; Nov 23 '07, 06:12 AM. Reason: adding code tags
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by shilpareddy2787
    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.
    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";
    }
    }

    Please suggest if any changes in this code or suggest me another way.
    Thanks.
    If any,whats the error message ???
    what are you getting in returnRows??

    it seems nothing wrong in your code....

    Comment

    • shilpareddy2787
      New Member
      • Nov 2007
      • 11

      #3
      Originally posted by dip_developer
      If any,whats the error message ???
      what are you getting in returnRows??

      it seems nothing wrong in your code....
      Hello,

      I am getting return rows as -1 when I gave correct user name , password and wrong username and password. I don't know why it is taking as -1. Please help me

      Thank you

      Comment

      • dip_developer
        Recognized Expert Contributor
        • Aug 2006
        • 648

        #4
        Originally posted by shilpareddy2787
        Hello,

        I am getting return rows as -1 when I gave correct user name , password and wrong username and password. I don't know why it is taking as -1. Please help me

        Thank you
        In case of ExecuteNonquery if a Rollback occurs, the return value is -1. So I think no transaction is happening...... check the table field name,table name and if possible change the fieldname username/password to something like user_name/pass_word...... ......hope for good...give your feedback

        and change your sql query to...

        [CODE=cpp]
        "select username,passwo rd from signup where username='" + uname + "' and password = '" + pword + "' ";
        [/CODE]

        dont use '&&'

        Comment

        • shilpareddy2787
          New Member
          • Nov 2007
          • 11

          #5
          Originally posted by dip_developer
          In case of ExecuteNonquery if a Rollback occurs, the return value is -1. So I think no transaction is happening...... check the table field name,table name and if possible change the fieldname username/password to something like user_name/pass_word...... ......hope for good...give your feedback

          and change your sql query to...

          [CODE=cpp]
          "select username,passwo rd from signup where username='" + uname + "' and password = '" + pword + "' ";
          [/CODE]

          dont use '&&'
          I did the same as you told but no use. again it takes return rows as -1.

          Comment

          Working...