ixalmida wrote:Firstly, I didn't even suggest a user lockout. You'll clearly note the word "Sleep" as the first word in my comment section.
I had assumed that was the general idea for that section in your code. However, re-reading the OP's first post, I see now that they wanted to block the specific IP address.
Still, if someone else were to guess passwords wrong two times, then a legitimate user comes along and accidentally fat-fingers a key once, your code above would then consider this the third attempt and then lock-out the legitimate user.
ixalmida wrote:Secondly, how would an attacker get a list of user names?
Since I don't know what this login system leads to, I can't answer that. Take PHPBuilder's login system for example. How would an attacker get a list of usernames? Simply by clicking on the "Members List" link.
ixalmida wrote:So instead of taking issue with me personally
Don't know why you're being so abrasive; I don't have any issue with you personally.
ixalmida wrote:why don't you just make a better, more timely suggestion if you have one?
Sure!
@: One way to do this would be with the user of either cookies or sessions. Before allowing them to even attempt to login, see if their IP address is in your "banned" table in the DB and if the timestamp field is within the range you specify (e.g. within the past 3 hours - whatever you'd like). If it isn't, then simply display the login form as normal.
Then, for every invalid login attempt, increment some counter variable (in the cookie or session from above). Then, before allowing them to login again, check if that counter variable is more than 2. If it is, add their IP to the database (with the current time) and deny any further login attempts.
Note that blocking via IP address has the following disadvantages/weaknesses:
Workstations at many schools/business/corporations/etc. all sit behind a common proxy/gateway, meaning that they share a very limited (perhaps even one) external IP addresses. In other words, if you lock-out one user, you could be blocking an entire building.
A new IP address is quite easy to get for free; there are numerous open proxies, free VPNs, etc. etc. out there.
I don't know if this still applies, but AOL had a number of proxy servers, and each request made by a single AOL user could have been serviced through any of those servers. In other words, it was very common in the past to see an AOL user's IP address to change many times from one request to another.