Show recaptcha after 3 wrong attempts

Asked

Viewed 163 times

1

I implemented the recaptcha on the site, but it is very expensive to users every time they are logged in click on the images, I wanted it to appear after 3 attempts, but I’m not getting, I want to do via JS...

1 answer

1


Face is very easy, you can use a global variable as in my example:

tentativas = 0;
//defino uma função ao clickar no botao
document.getElementById("enviar").addEventListener("click", logar);

function logar() {
    var login = document.getElementById("inpLogin").value;
    var senha = document.getElementById("inpSenha").value;
    
    tentativas += 1;
    //aqui sua tratativa para logar o usuario
    if(login=='admin' && senha=='admin'){
    	alert('logado');
    }else{
    	alert('usuario e senha incorreto, numero de tentativas: '+tentativas);
    }
    
    if(tentativas==3){
    	document.getElementById("recaptcha").style.display = 'block';
    }
}
<html>
  
  <body>
    <form action="#">
      <input type="text" id='inpLogin' size='10' placeholder='login'>
      <input type="password" id='inpSenha'  size='10' placeholder='senha'>
      <button id="enviar" type='button'>LOGAR</button>
    </form>  
    <br>
    <div id='recaptcha' style='display: none;'>
      <img src="https://developers.google.com/recaptcha/images/newCaptchaAnchor.gif" alt="" width='270'>
    </div>
  </body>

</html>

and then you leave the div with the recaptcha with the style display = none (or is hidden), and then you show it when the number of attempts is greater than 3.

  • Thank you so much for your help in !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.