Rank: Administration
Groups: Administration
Joined: 10/8/2008(UTC) Posts: 190  Was thanked: 1 time(s) in 1 post(s)
|
UPDATE Erwin 2018-11-06: go to here: Recaptcha 2018 Recaptcha 2018Hi There, A lot of times I get the question from customers to include captcha on their contact form or somewhere else in their site. That's why I decided to create a manual for this so other people can use this knowledge as well. This manual is for including reCAPTCHA in Sienn, and really, If you know how, It's really easy to implement. At first we need a public and a private key for the site, You can get this from here: https://www.google.com/recaptcha/admin/createYou can also recieve global key's so you can use the same key's for multiple sites but that is up to you. Now we have to download the reCAPTCHA dll from here: http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latestand copy it to the sites bin directory. Now we have to create an open control like this: Code:d:\inetpub\wwwroot\<site dir>\bin\Recaptcha.dll
==>END SYSTEMREFERENCE
Imports recaptcha
==>END IMPORTS
Dim recaptcha as new RecaptchaControl
recaptcha.Id="recaptcha"
recaptcha.PublicKey="<My public key>"
recaptcha.PrivateKey="<My private key>"
Controlplace.controls.add(recaptcha)
replace the key's and dir of the site or also copy the dll in the SiennCMS. And put this control somewhere in the form. ({!$Control.36.<constrol number>$!}) If we load the form now, we should already see the capcha.  We can also renew this captcha, but still we have to finish the check for the submitbutton. We can do this in "UserEscape formulier datacheck" here we can place the following code: Code:select Case FormId
Case 1
If not MyForm.IsValid Then
return "Wrong Captcha"
End If
end Select
Of cource we need to check the formId And we are done. For more information about customizing this captcah you can look here: https://developers.google.com/recaptcha/docs/aspnet?hl=nlEdited by moderator Tuesday, November 6, 2018 9:41:33 AM(UTC)
| Reason: Not specified
|
|
|
|
Rank: Administration
Groups: Moderators, Administration, Member Joined: 10/8/2008(UTC) Posts: 44
|
To theme it, don't add the script as described in Google, but change you variables in the control: Code:recaptcha.theme = "clean"
so you get something like this: Code:Dim recaptcha as new RecaptchaControl
recaptcha.theme = "clean"
recaptcha.Id="recaptcha"
recaptcha.PublicKey="xxx"
recaptcha.PrivateKey="yyy"
Controlplace.controls.add(recaptcha)
styles can be found here: https://developers.google.com/recaptcha/docs/customization?hl=nl
|
|
|
|
Rank: Administration
Groups: Administration
Joined: 10/8/2008(UTC) Posts: 190  Was thanked: 1 time(s) in 1 post(s)
|
Recaptcha V2 and sienn ML Hi Guys, the implementation of reCaptcha V2 is a little bit different then for v1 see also the documentatation https://developers.google.com/recaptcha/introhaving the captcha appear on the site is the easy past. you just include a javascript (always https) and then Add a div for the captcha Code:<script src="https://www.google.com/recaptcha/api.js?hl=nl" async defer></script>
<div class="g-recaptcha" data-sitekey="<Site key>" data-theme="dark"></div>
you can give paramaters for theme and language of course. see configuration: https://developers.googl...tcha/docs/display#confignow the recaptcha is there still we have to validate this. this we still do in "UserEscape formulier datacheck (Global)" we can retrieve the captcha value the following way Code:Dim ReCaptchavalue as string = Request.form("g-Recaptcha-Response")
we have to create a functions which calls the google API for validation like this Code:Public Function Validate(EncodedResponse As String) As boolean
Dim client = New System.Net.WebClient()
Dim PrivateKey As String = "<Private Key......>"
Dim GoogleReply as string= client.DownloadString(String.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", PrivateKey, EncodedResponse))
' Dim captchaResponse = Newtonsoft.Json.JsonConvert.DeserializeObject()(GoogleReply)
' Return captchaResponse.Success
Return GoogleReply.contains("""success"": true")
End Function
now we still only have to check the key from the form request. In siennML this looks like this, in Sienn4 we just return the error as string. Code:Select Case FormId
Case 4
Dim ReCaptchavalue as string = Request.form("g-Recaptcha-Response")
If Not Validate(ReCaptchavalue) Then
Dim errorItem As SError.SErrorItem = New SiennDataObject.SError.SErrorItem(SiennDataObject.SEnum.SErrorTypes.Error_FieldCheck_NotDateTime,"ReCaptchavalue", 0, 0, 0, "U heeft de Captcha verkeerd ingevuld")
SError.Add(errorItem)
Return False
End If
End Select
Thats's it. see http://stackoverflow.com...-in-asp-nets-server-side for more solutions
|
|
|
|
Rank: Administration
Groups: Moderators, Administration, Member Joined: 10/8/2008(UTC) Posts: 44
|
1. Get or create a recaptcha secret key and private key at: https://www.google.com/recaptcha/admin#list (easiest to use the MCC-account of SIENN) 2a. Add to code UserEscape formulier datacheckCode:
Select Case FormId
Case 3 ' <-- change id to your form of course...
Dim ReCaptchavalue as string = Request.form("g-Recaptcha-Response")
If Not Validate(ReCaptchavalue) Then
Return "Your Recaptcha is invalid"
End If
End Select
2b. Add to the function of UserEscape formulier datacheckCode:
Public Function Validate(EncodedResponse As String) As boolean
Dim client = New System.Net.WebClient()
Dim PrivateKey As String = "aaaabbbcccddeeeeefff" ' <-- change PrivateKey with your private key from step 1
Dim GoogleReply as string= client.DownloadString(String.Format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}", PrivateKey, EncodedResponse))
Return GoogleReply.contains("""success"": true")
End Function
2c. error check the build/compile the UserEscape formulier datacheck3. add to your form these 2 lines before the send-button: Code:
<script src='https://www.google.com/recaptcha/api.js'></script>
<div class="g-recaptcha" data-sitekey="111122223333344444"></div> <!-- <-- change data-sitekey with the public key from step 1 -->
{!!Button_bevestig!!}
4. test it on the live website, inform the customer.
|
|
|
|
Rank: Administration
Groups: Administration
Joined: 10/8/2008(UTC) Posts: 190  Was thanked: 1 time(s) in 1 post(s)
|
Recaptcha V3. so, now there is V3, which we need to implement. V3 actually is easy, you need to register the keys here, just like for v2 https://www.google.com/recaptcha/admin/createAs an advise I would encourage you to enable the alerts. Then from the form Remove the Recaptcha v2 stuff and add this on top of the form Code:<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
<input type="hidden" name="action" value="validate_captcha">
<script src="https://www.google.com/recaptcha/api.js?render=reCAPTCHA_site_key"></script>
<script>
grecaptcha.ready(function() {
// do request for recaptcha token
// response is promise with passed token
grecaptcha.execute('reCAPTCHA_site_key', {action:'validate_captcha'})
.then(function(token) {
// add token value to form
document.getElementById('g-recaptcha-response').value = token;
});
});
</script>
be aware, you need to replace the site key twiceThen the rest is exactly the same as for V2. remember to also change the key on the back end if you are migrating.
|
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The Sienn Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close