error in login to home page

Page 1 of 1

2 Replies - 8606 Views - Last Post: 09 March 2013 - 10:48 PM

#1 briana evigan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-February 13

error in login to home page

Posted 09 March 2013 - 07:00 AM

hi all,
i am trying to develop an asp.net website bu i have an error in redirected from login form to the homepage

the code of my login.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "select count(*) from registration where UserName='" + TextBox1.Text + "'";
        SqlCommand Checkuser = new SqlCommand(cmdStr, con);
        int temp = Convert.ToInt32(Checkuser.ExecuteNonQuery().ToString());
        if (temp == 1)
        {
            string cmdStr2 = "select Password from Registration where UserName='" + TextBox1.Text + "'";
            SqlCommand pass = new SqlCommand(cmdStr2, con);
            string password = pass.ExecuteNonQuery().ToString();
            con.Close();

            if (password == TextBox2.Text)
            {
                Session["New"] = TextBox1.Text;
                Response.Redirect("Secure.aspx");
            }
            else
            {
                Label1.Visible = true;
                Label1.Text = "Invalid Password...!!";
            }
        }
        else
        {
            Label1.Visible = true;
            Label1.Text = "Invalid UserName...!!";
        }

    }
}


the debug error


Posted Image

snapshot of the database


Posted Image


although the user is registered in the database, the debug said "invalid user name"
i couldn't know where is the error??


Is This A Good Question/Topic? 0
  • +

Replies To: error in login to home page

#2 Takk  Icon User is offline

  • D.I.C Head

Reputation: 40
  • View blog
  • Posts: 111
  • Joined: 08-March 13

Re: error in login to home page

Posted 09 March 2013 - 11:09 AM

Using ExecuteNonQuery is designed to not return a value, it is very likely that password is not being populated correctly on line 26 above. This should be ExecuteQuery. However keep in mind, the method which you are using to create your query string leaves you open to SQL injection attacks and should likely be revisited if this site will go live. A search should turn up some options as to a better explanation of this and how you can avoid it.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#3 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,276
  • Joined: 28-March 11

Re: error in login to home page

Posted 09 March 2013 - 10:48 PM

Duplicate... closed
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1