locked
How to implement google recaptcha just by javascript for any web site RRS feed

  • Question

  • User264732274 posted

    i just found the below code in a web site. now tell me how to use it for any web site to implement google captcha ?

            var onloadCallback = function() {
                grecaptcha.render('recaptcha', {
                    'sitekey' : 'my keys',
                    'hl' : 'GB',
                    'callback' : IsRightCaptcha
                });
            };
    
            var IsRightCaptcha = function(response) {
                $('#g-recaptcha-response').val(response);
            };

    one server side function

            public static bool CheckCaptcha(string captchaResponse, string ipAddress)
            {
                using (var client = new WebClient())
                {
                    var response = client.DownloadString(new Uri(string.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}&remoteIp={2}", ConfigurationManager.AppSettings["CaptchaSecret"],captchaResponse,ipAddress)));
                    return JsonConvert.DeserializeObject<RecaptchaResponse>(response).Success;
                }
            }

    the above server side function CheckCaptcha is required at all ?

    please guide. thanks

    Tuesday, October 4, 2016 10:31 AM

Answers

  • User264732274 posted

    this link https://y-designs.com/blog/google-recaptcha-v2-on-a-dynamic-page/

    https://magecomp.com/blog/google-no-captcha-recaptcha-one-more-step-against-spam/

    http://www.aspsnippets.com/Articles/Validate-Google-RECaptcha-on-Client-Side-using-JavaScript-and-jQuery-in-ASPNet.aspx

    will help to implement to recaptcha just by js only. thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 4, 2016 11:38 AM
  • User264732274 posted

    solved this way

     the below code will render google re-captcha just by only js
     -------------------------------------------------------------
     
             var onloadCallback = function() {
                 grecaptcha.render('recaptcha', {
                     'sitekey' : 'my site keys',
                     'hl' : 'GB',
                     'callback' : correctCaptcha
                 });
             };
     
             var correctCaptcha = function(response) {
                 $('#g-recaptcha-response').val(response);
             };
    
     this script is required
     -------------------------
     <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
     
     
    this below code will check user select right images from captcha
    -----------------------------------------------------------------
    var response = grecaptcha.getResponse();
    //recaptcha failed validation
    if (response.length == 0) {
        $('#recaptcha-error').show();
        //alert('Provide input for captcha');
        $('.registrationError').empty();
        $('.registrationError').append('<li>Provide input for captcha</li>').show();
        return false;
    }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 5, 2016 9:17 AM

All replies

  • User264732274 posted

    this link https://y-designs.com/blog/google-recaptcha-v2-on-a-dynamic-page/

    https://magecomp.com/blog/google-no-captcha-recaptcha-one-more-step-against-spam/

    http://www.aspsnippets.com/Articles/Validate-Google-RECaptcha-on-Client-Side-using-JavaScript-and-jQuery-in-ASPNet.aspx

    will help to implement to recaptcha just by js only. thanks

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 4, 2016 11:38 AM
  • User264732274 posted

    solved this way

     the below code will render google re-captcha just by only js
     -------------------------------------------------------------
     
             var onloadCallback = function() {
                 grecaptcha.render('recaptcha', {
                     'sitekey' : 'my site keys',
                     'hl' : 'GB',
                     'callback' : correctCaptcha
                 });
             };
     
             var correctCaptcha = function(response) {
                 $('#g-recaptcha-response').val(response);
             };
    
     this script is required
     -------------------------
     <script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit" async defer></script>
     
     
    this below code will check user select right images from captcha
    -----------------------------------------------------------------
    var response = grecaptcha.getResponse();
    //recaptcha failed validation
    if (response.length == 0) {
        $('#recaptcha-error').show();
        //alert('Provide input for captcha');
        $('.registrationError').empty();
        $('.registrationError').append('<li>Provide input for captcha</li>').show();
        return false;
    }
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 5, 2016 9:17 AM