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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:25:59+00:00 2026-05-23T04:25:59+00:00

I want to limit the failed login attempts. For example, if a specific user

  • 0

I want to limit the failed login attempts. For example, if a specific user attempt to login with wrong username or password 4 times, i should show the CAPTCHA 4th time instead of blocking for some specific time, and keep showing CAPTCHA unless he supplies valid username and password. Once the user has successfully logged in, the login attempt is reset to ZERO.

Is the idea of checking the username instead of IP address OK in security point of view? Can this approach be implemented without using database?, as I think I don’t need to store time because i will just show recaptcha?
Please give your opinion.

  • 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-23T04:26:00+00:00Added an answer on May 23, 2026 at 4:26 am

    You don’t want to use the database for the ‘number of failed logins’-check? Then just use a cookie and check it. Sure, they can remove it, but it’s a hassle.

    However, I suspect that you already are getting the username and password from the database, why not also fetch the last number of failed logins while you are at it?

    if (isset($_POST['submit_login'])) {
    
        if (isset($_POST['username']) && isset($_POST['password'])) {
            $username = mysql_real_escape_string($_POST['username']);
            $password = mysql_real_escape_string($_POST['password']);
            // id = unique primary key
            $rs = mysql_query('SELECT id,Username,Password,Failed_logins,IP_address FROM Users WHERE Username = '.$username.'');
            $num = mysql_num_rows($rs);
            if ($num > 0) {
                // I would add a password hash here to $password, and check against the hashed Password from the database
                // But let's check the clean passwords
                $row = mysql_fetch_array($rs);
                if ($password == $row['Password']) {
                    // Successful login, set session or whatever you need
                    // Reset failed logins
                    mysql_query('UPDATE Users SET Failed_logins = 0 WHERE id = '.$row['id'].'');
                    header('location: success.php');
                } else {
                    // Failed password check
                    if ($row['Failed_logins'] > 3) {
                        // Redirect to captcha
                        header('location: captcha.php');
                    } else {
                        $ip = $_SERVER['REMOTE_ADDR'];
                        if ($row['IP_address'] != $ip) {
                            // New ip adress, reset failed logins
                            $failed_logins = 0;
                        } else {
                            // Increment failed logins
                            $failed_logins = $row['Failed_logins']+1;
                        }
                        mysql_query('UPDATE Users SET Failed_logins = '.$failed_logins.',IP_address = '.$ip.' WHERE id = '.$row['id'].' ');
                    } // End check Failed_logins > 3
                }
            } else {
                // No such Username found in database
                $error = 'no_such_username';
            } // End username check from database
    
        } else {
            // Either username or password is missing
            $error = 'incomplete_form';
        } // end check for username and password
    
    } // end main submit_login check
    

    Something like that.

    EDIT:

    This is really old code and I see some problems with it now. But, at least you should always use PDO (prepared statements) for inserting data in your database.

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

Sidebar

Related Questions

I want to limit access to username+password table to one query pattern like: SELECT
I want to limit port 80 so that only one user can use it.
I want to limit the system resources available to queries run by specific users
I want to limit the length of a textfield, so that a user can
I want to limit my users to a directory and its sub directories but
I want to limit the number of records returned by calling ROW_NUMBER(), but I
I want to limit a report to return records from Date A through Date
I want to limit access to images, therefore, I will be putting them outside
I want to limit my SWF file so that it cannot be stolen and
I want to limit clients to an upper limit of number of calls to

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.