Solved

Show alert after 3 wrong login attempts

Posted on 2011-09-27
5
307 Views
Last Modified: 2012-06-27
So, I'm trying to create an if/else statement that sends a warning to someone who has tried more than 3 invalid login attempts. When someone tries to login it looks to a MySQL db and if a username with that password matches, it forwards them on. But if it’s wrong I want it to begin a count and then at 4 wrong attempts display an error message. So right now, here’s what I have:

On the login page:
<login form>
if ($i>3) {echo “error message”;}

On the check login info page:
if (login is right)
{ assign variables and pass on}
else
{ $i++;}

Any help would be appreciated!
0
Comment
Question by:brendan-amex
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Rik-Legger
ID: 36710632
You could do this by using sessions,

session_start();

if ($_SESSION['login_attempts'] > 3) {
    echo  'error message';
    die;
}

if (login is right) {
    // 
} else {
    $_SESSION['login_attempts']++;
}

Open in new window

0
 
LVL 13

Expert Comment

by:Hugh McCurdy
ID: 36710794
Sessions only works if your record the 3 attempts in the database.  Otherwise someone could just close the browser and get 3 more sessions.  A hacker would figure that trick out quickly and just destroy the session variable using software.

What I would do is record the attempts in the database record belonging to the user.

The simple approach is to simply keep a counter in the database record.  Be sure you reset the counter to 0 if the login attempt is successful.  If the counter gets to 3, then lock the account, produce instructions on how to unlock it, etc.

A more complicated approach has the counter but also records the time of each login attempt (successful or not).  You'd keep a history of at least 3 but it could be more, like 10.  This might help if you wanted to investigate further.
0
 

Author Comment

by:brendan-amex
ID: 36710921
I see, recording it in a database makes sense but what if a couple people enter a wrong password at the same time and then it locks out for all of them? Could I grab the IP address from the computer and put that in the database as well to associate with it....
0
 
LVL 13

Accepted Solution

by:
Hugh McCurdy earned 500 total points
ID: 36711001
I guess I wasn't clear.

You want to store the failed attempts in the record (table row) that  is associated with the user attempting to login.

If more than one user is trying to login under the same user name from different locations, you have enough of a problem to justify locking the account right then.

Your idea of IP address is good.  If you know the user is in Detroit and you start getting login attempts from an IP in Armenia, you might want to know about it.
0
 

Author Closing Comment

by:brendan-amex
ID: 36711761
I understand what you're saying now. I have a CAPTCHA come up after 3 wrong attempts from the same IP address. Hopefully this helps against bot attacks. Thanks for your help.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question