📜 ⬆️ ⬇️

CAPTCHA for your site

Today I will talk about how you can quickly and easily screw the CAPTCHA check on your site.


For those who do not know, CAPTCHA is an automated Turing test to distinguish between computers and people. More information about what CAPTCHA can be found on Wikipedia .


In this example, I used the free service recaptcha.net . You will have to register to work with it, because you will need Public and Private keys.
')


This is how the reCAPTCHA API works:


I will take a sample code for reCAPTCHA implementation written for ASP.NET , but you can find it for almost all languages here .

To get started:


  1. It is necessary to download the reCAPTCHA library .
  2. Add Recaptcha.dll to the directory / bin / of your site.
  3. Paste the following reCAPTCHA control into the page where you want to implement the check:


<% @ Register TagPrefix = "recaptcha" Namespace = "Recaptcha" Assembly = "Recaptcha"%>

< recaptcha: RecaptchaControl
Id = "recaptcha"
runat = "server"
PublicKey = "1234567890"
PrivateKey = "0987654321" />



* Where PublicKey and PrivateKey are the keys you received during registration.

All you have left is to check the property Page.IsValid in the code.

For example, like this:

<% @ Page language = "VB"%>
<% @ Register TagPrefix = "recaptcha" Namespace = "Recaptcha" Assembly = "Recaptcha"%>
< script runat = server >
Sub btnSubmit_Click (ByVal sender As Object, ByVal e As EventArgs)
If Page.IsValid Then
lblResult.Text = "You Got It!"
lblResult.ForeColor = Drawing.Color.Green
Else
lblResult.Text = "Incorrect"
lblResult.ForeColor = Drawing.Color.Red
End if
End sub
</ script >
< html >
< body >
< form runat = "server" >
< asp: Label Visible = false ID = "lblResult" runat = "server" />

< recaptcha: RecaptchaControl
Id = "recaptcha"
runat = "server"
PublicKey = "1234567890"
PrivateKey = "0987654321"
/>
<Br />
< asp: Button ID = "btnSubmit" runat = "server" Text = "Submit" OnClick = "btnSubmit_Click" />
</ form >
</ body >
</ html > * This code was highlighted with Source Code Highlighter .


And it's all.
PS
If you once developed your Captcha module, I will be glad if you share your implementation version.

* The original post was posted on my blog .

Source: https://habr.com/ru/post/30556/


All Articles