Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7922397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T16:56:18+00:00 2026-06-03T16:56:18+00:00

I have developed a web application in visual studio 2010 and am attempting to

  • 0

I have developed a web application in visual studio 2010 and am attempting to add a user login system to this application. So far I am having trouble validating the users password, as the program informs me that all passwords are incorrect even if it matches the one associated to that username. This is the code I have written son far:

    protected void n_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "select count(*) from Registration where UserName='" + TextBoxUserName.Text + "'";
        SqlCommand CheckUser = new SqlCommand(cmdStr, con);
        int Temp = Convert.ToInt32(CheckUser.ExecuteScalar().ToString());
        if (Temp == 1)
        {
            string cmdStr2 = "Select Password from Registration where UserName ='" + TextBoxUserName.Text + "'";
            SqlCommand pass = new SqlCommand(cmdStr2, con);
            string password = pass.ExecuteScalar().ToString();
            con.Close();

            if (password == TextBoxPassword.Text)
            {
                Session["New"] = TextBoxUserName.Text;
                Response.Redirect("HomePage.aspx");
            }
            else
            {
                Label1.Visible = true;
                Label1.Text = "Password is invalid";
            }
        }
        else
        {
             Label1.Visible = true;
             Label1.Text = "Username is invalid";
        }


    }
}

}

Regardless of what password is entered the program will output ‘password is invalid’ which indicates that the issue is with the first part of the if statement? or the variables it uses?
It might also be worth mentioning that an invalid username flags up in the same way, and this works fine.

Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T16:56:20+00:00Added an answer on June 3, 2026 at 4:56 pm

    what you’re doing seems way too complex for what it’s supposed to do..

    edit: i editted my answer after user commented:

     public bool Login(String uName, String pasw)
    {
        using (SqlConnection myConnection = new SqlConnection(connString))
        {
            string oString = "Select ID from yourTable where username = @username AND paswoord = @password";
            SqlCommand oCmd = new SqlCommand(oString, myConnection);
            oCmd.Parameters.AddWithValue("@username", uName);
            oCmd.Parameters.AddWithValue("@password", pasw);
            string id = null;
            myConnection.Open();
            using (SqlDataReader oReader = oCmd.ExecuteReader())
            {              
                while (oReader.Read())
                {
                    id = oReader["id"].ToString();
                }
                myConnection.Close();
            }
            if (id == null)
            {
                return false;
            }
            else
            {
                return true;
            }         
        }
    }
    

    you could try something like this. Also, it might have nothing to do with it, but some databases dont like it when you name an attribute “password”, you could try changing it to “pw” or “pasw” or whatever.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam using visual studio 2010. i have developed one web application. my iis application
I have visual studio 2010 at home and have developed a web application. I
I have a ASP.Net web application developed on visual studio 2010 and it is
I have developed a web application in Visual Studio 2008 and want to publish
I have developed an ASP.NET web application in visual studio 2008. I want to
I have developed a web application in asp.net in visual studio 2008. Its working
I have developed an ASP.NET web application in Visual Studio 2008. I have an
I have an ASP.NET web application developed in Visual Studio 2008, composed of 3
I'm building an ASP.net application using Visual Studio Web Developer 2010 Express and have
I have an ASP.NET MVC 3 .NET application under Visual web developer Express 2010.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.