update: do not use sleep () to limit the speed! it makes no sense. I do not have a better solution at hand.
only sleep(1); good start sleep(1); after a failed login attempt, it’s easy to implement, with almost no errors.
1 second for a person is not so much (especially because attempts to enter the system by people are often not interrupted), but 1 sec / brute force attempt ... sloooow! dictionary attacks may be another problem, but they are in the same domain.
if an attacker also starts connecting to work around this, you are dealing with a kind of DOS attack. the problem is resolved (but now you have another problem).
Some things you should consider:
- If you block sole IP accounts, there may be problems with private networks.
- If you block soley accounts based on the username, denial of service attacks will again know the known usernames.
- IP / username based blocking (where the username is attacked) may work better
my suggestion: full blocking is undesirable (DOS), so the best alternative would be: counting login attempts for a specific username from a unique IP address. you can do this with a simple failed_logins: IP/username/failed_attempts table failed_logins: IP/username/failed_attempts
if login failure, wait(failed_attempts); seconds. every xx minutes, run a cron script that will reduce failed_logins:failed_attempts by one.
Sorry, I can’t provide a ready-made solution, but this should be trivial to implement.
OK OK. here's the pseudo code:
<?php $login_success = tryToLogIn($username, $password); if (!$login_success) { // some kind of unique hash $ipusr = getUserIP() . $username; DB:update('INSERT INTO failed_logins (ip_usr, failed_attempts) VALUES (:ipusr, 1) ON DUPLICATE KEY UPDATE failed_logins SET failed_attempts = failed_attempts+1 WHERE ip_usr=:ipusr', array((':ipusr' => $ipusr)); $failed_attempts = DB:selectCell('SELECT failed_attempts WHERE ip_usr=:ipusr', array(':ipusr' => $ipusr)); sleep($failed_attempts); redirect('/login', array('errorMessage' => 'login-fail! ur doin it rong!')); } ?>
disclaimer: this may not work in certain regions. The last thing I heard was that in Asia there is a whole country NATed (also, they all know kung fu).
stefs
source share