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

  • Home
  • SEARCH
  • 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 1058589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:02:52+00:00 2026-05-16T18:02:52+00:00

I created this simple login page. It’s supposed to display in the label text

  • 0

I created this simple login page. It’s supposed to display in the label text like “Wrong user” when user doesn’t exist, “Wrong password” when password entered is incorrect, etc.

But whenever I try and login it ALWAYS displays “Wrong user” when the user does exist in the table. I have entered usernames and passwords manually, not using any stored proceedure for that in this application.

Here’s the code; please tell me what am I doing wrong. Apparently it’s some logical error.

Default.cs file:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();

    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        if (con.State == ConnectionState.Closed)
        {
            con.Open();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        Int32 d = checkUser(UserName.Text, Password.Text);
        if (d == -1)
        {
            Label1.Text = "Wrong user";

        }
        if (d == -2)
        {
            Label1.Text = "Wrong password";
        }

        if (d == 2)

        {
            Label1.Text = "Login Successful";

        }
    }


    private Int32 checkUser(String u, String p)
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "LogInCheck";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Connection = con;
        cmd.Parameters.Add("@u", SqlDbType.VarChar, 50).Value = u;
        cmd.Parameters.Add("@p", SqlDbType.VarChar, 50).Value = p;
        SqlParameter p1 = new SqlParameter("@ret", SqlDbType.Int);
        p1.Direction = ParameterDirection.ReturnValue;
        cmd.Parameters.Add(p1);
        cmd.ExecuteNonQuery();
        Int32 k = Convert.ToInt32(cmd.Parameters["@ret"].Value);
        return k;
    }
}

.aspx file:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                Username :&nbsp;
                <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                <br />

                Password :
                <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                &nbsp;

                <asp:Button ID="Button1" runat="server" Text="Login" onclick="Button1_Click"/>
                <br />

                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </div>
        </form>
    </body>
</html>

My stored procedure, LogInCheck:

ALTER PROCEDURE LogInCheck
    (
        @u varchar(50),
        @p varchar(50)
    )

AS
    Declare @ap varchar(50)
    Select @ap from tbuser where uname=@u
    if @ap is null
        begin
            return -1
        end
    else
        if @ap=@p
            return 1
        else
            return -2
  • 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-05-16T18:02:52+00:00Added an answer on May 16, 2026 at 6:02 pm

    Your select query is not putting any value into @ap. Try this:

    Select @ap=<col_name> from tbuser where uname=@u
    

    Update
    Try putting a begin and end after you’ve started your main else.

    Declare @ap varchar(50)
    Select @ap from tbuser where uname=@u
    if @ap is null
    begin
    return -1
    end
    else 
    begin         --Here
    if @ap=@p
    return 1
    else 
    return -2
    end          --And here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to see a simple Login Application, not as simple as this
I have created a simple login page which is based on the sessions. session_start();
I am very new to flex, i have created a simple login page in
Consider a simple table with an auto-increment column like this: CREATE TABLE foo (
I just created a project so my Solution Explorer looks like this: (source: kalleload.net
I am trying to create a simple login page in ASP.NET C# but am
I have created a Django app. I have a registration page(simple HTML form) in
I am trying to create a simple user maintenance page for a school project.
I'm building an asp.net page that is designed to display links for a user
an anyone look at this simple code (?) and tell me what's wrong please?

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.