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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:47:26+00:00 2026-05-30T17:47:26+00:00

I am building a login form. If the user attempts to login with invalid

  • 0

I am building a login form. If the user attempts to login with invalid username/password for 3 attempts then the submit button must be disabled for a given duration.

How can I do that?

Here is my existing code:

protected void Button1_Click(object sender, EventArgs e)
{
    int count = 0;
    string username = TextBox1.Text.Trim();
    string password = TextBox2.Text.Trim();
    String connString = ConfigurationManager.ConnectionStrings["Myconnection"].ToString();
    SqlConnection conn = new SqlConnection(connString);
    SqlCommand cmd = new SqlCommand("Login", conn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@username", username);
    cmd.Parameters.AddWithValue("@password", password);
    conn.Open();
    SqlDataReader read = cmd.ExecuteReader();
    read.Read();

    if (read.HasRows)
    {
        Session["LoggedIn"] = "correct";
        Response.Redirect("WebForm2.aspx", false);
    }
    else
    {
        Label1.Visible = true;
        Label1.Text = "Wrong user/password";
        conn.Close();
    }

    if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
    {
        Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
        TextBox1.Enabled = false;
        TextBox2.Enabled = false;
        Button1.Enabled = false; // Button1 is the submit button
    }
    else
    {
        // Otherwise, increment number of tries.
        ViewState["Tries"] = System.Convert.ToInt32(ViewState["Tries"]) + 1;
        if (System.Convert.ToInt32(ViewState["Tries"]) == 2)
            Label1.Text = "Exceeded 3 times Attempts.Please Login after some time";
    }
}
  • 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-30T17:47:27+00:00Added an answer on May 30, 2026 at 5:47 pm

    For this you can create a table in your code or in database something like

    LockingTime
    
    Userid   LockTime  LockedDateTime
    1          30       01/03/2012 12:30
    

    As per th table

    UserId = id of the user locked
    LockTime - amount of time user Get locked
    LockDateTime - DateTime when user account locked
    
    1. When user login fails three time you enter data in table as explained…

    2. Now when user tries to login to system you should check

      select * from table name userid=@userid and GetDate() >
      DATEADD (mi, LockTime, LockDateTime)

    Note : query is just a suggession this not actual query as i m not added lockdate + locktime which is depends on the database and function avilable

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

Sidebar

Related Questions

Building a simple login page. If the user types in a password and password
I'm building a login form that will validate the login against a database, then
I am building on a standard form driven user login panel. Works well enough.
I want to have a login form on a charity website I am building
I am building a new website where a user can login. I see three
I'm building site where user will register, login, switch to other users page, read
I am currently building a dynamic form that allows the user to add as
I am building a ZendFramework application which as a login form asking for an
I need to save a user's login information in encrypted form for this application
I'm building(trying ... ) an iPhone application. My first user story is a login

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.