Appears recaptcha after 3 wrong attempts [closed]

1

I implemented the recaptcha on the site, but it is very costly to users every time they log in to click on the images, I wanted it to appear after 3 attempts, but I can not do it, I want to do it via JS ...

    
asked by anonymous 27.09.2018 / 21:23

1 answer

1

Dude, you can use a global variable like 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 div with recaptcha with style display = none (or hidden), and then you show it when the number of retries is greater than 3. >     

28.09.2018 / 15:41