1

I am using Google reCaptcha v3. i am trying to implement it onto my aspx page.When i first load my page i can get a token back. However when i click on a button to process my page it comes back with a "No reCaptcha clients exits". I did do a google search for this and nothing has came up to solve my issue. How can i verify a human or bot interaction?

this is what i have on my aspx page:

<div id="RegistrationForm">
  <input type="text" id="FirstName" runat="server" value="" valtype="required" maxlength="150" />
  <input type="text" id="LastName" runat="server" value="" valtype="required" maxlength="150" />
  <input runat="server" id="Email" type="text" value="" valtype="required;regex:email" maxlength="350"/>
  <input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response"/> <br />
  <div class="g-recaptcha" data-sitekey="SiteKey" data-callback="submit"></div>
  <input id="btnProcessOrder" type="button" name="ProcessOrder" onclick="confirmed = false;capt();" value="Save" />
</div>

this is What i tried

<script src="https://www.google.com/recaptcha/api.js?render=SiteKey"></script>
<script type="text/javascript">
    //so when i load the page it gets my token and i can assign the value to g-recaptcha-response
   grecaptcha.ready(function() {
       grecaptcha.execute('SiteKey', { action: 'homepage' }).then(function (token) {
           console.log(token);
           document.getElementById('g-recaptcha-response').value = token;

  });
});


 Then when i try to verify the response as follows i get the error or it just does nothing:
function capt() {
var response = grecaptcha.getResponse();
$.ajax({
   type: "POST",
   url: 'https://www.google.com/recaptcha/api/siteverify', 
   data: {"secret" : "SecretKey", "response" : response, "remoteip":"localhost"},
   contentType: 'application/x-www-form-urlencoded',
   success: function(data) { console.log(data); }
});// i call this function on my button
}
</script>

Most of the code i found is for php and i can not use that.How do i get this to work correctly?. Your response is highly appreciated

marry
  • 153
  • 2
  • 3
  • 15
  • Console `grecaptcha.getResponse();` and let us know what you get? – Brian Nezhad Jun 20 '19 at 14:51
  • 1
    @Farhad it says "ƒ (M,v){if(v=(M=void 0===M?pU():M,window.___grecaptcha_cfg.clients)[M],!v)throw Error("Invalid reCAPTCHA client id: "+ M);return da(v.id).value}" but i am using the exact same site key that they gave – marry Jun 20 '19 at 15:01
  • 1
    `grecaptcha.getResponse();` is returning back a function. See what happens when you call `response()`; What is your `console.log(data);` outputting? – Brian Nezhad Jun 20 '19 at 15:04
  • It doesn't even reach that console, it just breaks at grecaptcha.getResonse() – marry Jun 20 '19 at 16:35
  • Are you sure you are including `/recaptcha/api.js` correctly?, Also can you confirm if you have set up `grecaptcha.render`? if yes, you can have a callback parameter, example `verifyCallBack` and then right function for `verifyCallBack` – Brian Nezhad Jun 20 '19 at 17:52
  • Then right function for `verifyCallBack` to capture the response as such `var verifyCallBack = function(response) { console.log(response); };` – Brian Nezhad Jun 20 '19 at 17:57
  • No I don't have any recaptcha.render() function, do I include that in the capt() function or do I create a new function for it? – marry Jun 20 '19 at 19:42
  • @Josue has answered this, please follow that instruction. – Brian Nezhad Jun 20 '19 at 19:53

2 Answers2

1

According to the above comments:

You create a render function as following

grecaptcha.render('example3', {
    'sitekey' : 'your_site_key',
    'callback' : verifyCallback,
});

Then to get the response from the captcha you create a variable which will store the data as such:

var verifyCallBack = function(response) { 
    console.log(response); 
};
Josue Arce
  • 48
  • 3
  • it says ERROR for site owner: Invalid key type on the grecaptcha.rendor method. which really doesnt make any sense if its the site key that they gave me,i even deleted and created a new key – marry Jun 21 '19 at 08:23
  • @marry make sure you didn't put a restriction on the key or if is correct key for v2 or v3 version of recaptcha, [Setting Doc](https://developers.google.com/recaptcha/docs/settings). I also recommend reading the [reCAPTCHA doc](https://developers.google.com/recaptcha/intro), is very well maintained. – Brian Nezhad Jun 25 '19 at 12:44
0

Here we already have a same type of question : How to implement reCaptcha V3 in ASP.NET Please check these answers .

Also you can check this demo project for reference .https://github.com/NIHAR-SARKAR/GoogleRecaptchav3-example-In-asp.net

Nihar Sarkar
  • 1,187
  • 1
  • 13
  • 26