If more than 3 wrong send, show captcha

On the login page of my sites, users must correctly enter the username, password and tracking code if they want to enter a user area. But to anyone, firstly, I do not like captcha. And, on the other hand, you know, Internet security and the fact of spam.

So, for the first, second and third time I do not want to show captcha, but I want to show more than 3 misconceptions. But I do not know how to implement this! I tried

$_SESSION['wrong_submit'] = 1; 
$_SESSION['wrong_submit']++;

Of course not. Please, could you help me, how can I do this?

+4
source share
3 answers

login_attempts. .

:

+-----------+------+------+
|  user_id  |  ip  | date |
+-----------+------+------+

, , :

SELECT count(ip) AS failed_attempts
FROM login_attempts
WHERE ip = $ip
  AND date < (NOW - INTERVAL 24 HOUR)

, PHP-, , 3, -, :

if ($data['failed_attempts'] >= 3) {
    // display captcha...
}
+10

, ( ..).

cookie. , , , , - cookie, , . , .

, , captcha.

+5

You can try this way ....

<?php 
    $_SESSION['wrong_pword_count']=0;

    if($stored_password != $provided_password){
        if($_SESSION['wrong_pword_count']<3){
            $_SESSION['wrong_pword_count'] = $_SESSION['wrong_pword_count']+1;
        }
    } else {
        $_SESSION['wrong_pword_count']=0;

    }

    if($_SESSION['wrong_pword_count']>=3){
        echo "Show captcha here";
    }
+2
source

Source: https://habr.com/ru/post/1527071/


All Articles