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 8995585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:38:23+00:00 2026-06-15T23:38:23+00:00

I’ve made a basic Login Page using textboxes. I’m validating the users from the

  • 0

I’ve made a basic Login Page using textboxes. I’m validating the users from the database created. Below is my backend code:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    SqlDataReader sdrDatanew = null; //Read rows one by one.
    string strnew;
    string connectionString = WebConfigurationManager.ConnectionStrings["Gen_LicConnectionString"].ConnectionString; //Define new connectionstring
    SqlConnection connew = new SqlConnection(connectionString); //establishes a new sql connection
    connew.Open(); //Opens Connection
    strnew = "select User_Type from User_Details where User_Type='" + ddlUserSel.SelectedItem.Value + "' AND LoginID = '" + txtUserName.Text + "' AND Password = '" + txtPassword.Text + "'";
    SqlCommand sqlCommnew = new SqlCommand(strnew, connew); //passes the command and connection
    sdrDatanew = sqlCommnew.ExecuteReader(); //For select command

    int userType = 0;

    if (sdrDatanew.HasRows)
    {
        if (sdrDatanew.Read())
        {
            userType = Convert.ToInt32(sdrDatanew["User_Type"].ToString());
        }
    }

    switch (userType)
    {
        case 0:
            Response.Redirect("Lic_Gen.aspx");
            break;
        case 1:
            Response.Redirect("Cust_Page.aspx");
            break;
        default:
            lblDisp.Text= "Invalid User/Password";
            break;
    }

    connew.Close();
}

This is my frontend code:

<div>
    <h2 class="style12">
        LOGIN</h2>
    <p class="style10">
        &nbsp;</p>
    <table align="center" cellpadding="2" cellspacing="5" style="border-width: thick;
        border-style: outset; height: 195px;" class="style14">
        <tr>
            <td class="style16" style="border-style: none; font-family: 'Times New Roman', Times, serif;
                font-size: 17.5px; font-weight: bold; font-style: normal">
                User Type</td>
            <td class="style17">
                <asp:DropDownList ID="ddlUserSel" runat="server" Height="25px" Width="260px" CssClass="drp">
                    <asp:ListItem Value="0">Admin</asp:ListItem>
                    <asp:ListItem Value="1">Customer</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
        <tr>
            <td class="style16" style="border-style: none; font-family: 'Times New Roman', Times, serif;
                font-size: 17.5px; font-weight: bold; font-style: normal">
                Login
            </td>
            <td class="style17">
                <asp:TextBox ID="txtUserName" runat="server" Width="250px" CssClass="Textbox1" MaxLength="15"></asp:TextBox>
                <asp:RequiredFieldValidator ID="reqUserName" runat="server" ErrorMessage="*" ForeColor="Red"
                    ControlToValidate="txtUserName" Font-Size="Large"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style16" style="font-family: 'Times New Roman', Times, serif; font-size: 17.5px;
                font-weight: bold; font-style: normal">
                Password
            </td>
            <td class="style17">
                <asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="250px" CssClass="Textbox1" MaxLength="15"></asp:TextBox>
                 <asp:RequiredFieldValidator ID="reqPassword" runat="server" ErrorMessage="*" ForeColor="Red"
                    ControlToValidate="txtPassword" Font-Size="Large"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                <asp:Label ID="lblDisp" runat="server" ForeColor="Red"></asp:Label>
            </td>
        </tr>
        <tr>
            <td colspan="2" align="center">
                &nbsp;<asp:Button ID="btnSubmit" runat="server" CssClass="btn1" Text="Submit" 
                    OnClick="btnSubmit_Click" Width="80px"/>
                &nbsp;&nbsp;
                <asp:Button ID="btnCancel" runat="server" CssClass="btn1" Text="Cancel" 
                    OnClick="btnCancel_Click" Width="80px"/>
            </td>
        </tr>
    </table>
</div>

Now I’m having the following issues:

  1. Irrespective of the user type, the page always gets redirected to Lic_Gen.aspx.
  2. Even if I enter the wrong password, the page still gets redirected to Lic_Gen.aspx.
  3. The page should also check whether the userType entered i.e. Admin or Customer should be valid with that particular Login ID and Password. But I can’t get to that either.

I know these issues are arriving because of the fact I’ve explicitly defined UserType value as 0.

When I tried converting it with the following code:
int userType = Convert.ToInt32(strnew); it doesn’t work.

So any guidelines on how to improve my basic page?

  • 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-15T23:38:23+00:00Added an answer on June 15, 2026 at 11:38 pm

    Based on provided code, possible problems are :

    1. No data returned in sdrDatanew, hence the userType always remains 0
    2. Data from DB returned under sdrDatanew["User_Type"] is always 0 (string), hence the userType always remains 0

    Please use above points to debug further and I see no issues in code.

    CAUTION : Your code is vulnerable to SQL Injection attack. Please read details @ http://en.wikipedia.org/wiki/SQL_injection. If you are planning to publish this web site somewhere, you will be in trouble for sure.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.