19 January 2012

reCAPTCHA : Free Captcha service for ASP.NET

What is reCaptcha?
  1. reCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows.
  2. It’s Free! Yep, reCAPTCHA is free.
  3. It’s Easy. reCAPTCHA is a Web service. As such, adopting it is as simple as adding
    a few lines of code on your site.
  4. It’s Accessible. reCAPTCHA has an audio test that allows blind people to freely
    navigate your site.
  5. It’s Secure. Most other CAPTCHA implementations can be easily broken.
  6. It’s Popular. Over 100,000 sites use reCAPTCHA, including household names like Facebook, Ticketmaster, and Craigslist.
  7. Whenever uses input data in reCaptcha control, they actually help digitizing books.
Moreover is very easy to integrate reCaptcha in our websites. Below are the steps
which are required to integrate it into a ASP.NET page.
Steps to Integrate reCaptcha in ASP.NET 

Step1:  Register for a reCaptcha key : As a first step we need to register for recaptcha keys. Navigate to Get reCaptcha URL to signup for the keys. After we register for the keys, we get a public and private keys which we need to use in our asp.net page. By default all keys work on localhost as well. 

Step2:  Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project. 
Step3:  Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:
Step4:  At the top of the aspx page, insert this: 
      <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

Step5:  Then insert the reCAPTCHA control inside of the form tag and Enter your Publickey and PrivateKey
 <recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="Red" PublicKey="" PrivateKey="" Height="30px" />
Step6:  Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission)
As an example I created a ASP.NET page whose markup and code behind code looks as given below:
Markup: (.aspx)


<asp:Label  Visible="true" ID="lblResult" runat="server" />
<recaptcha:RecaptchaControl ID="recaptcha" runat="server" Theme="Red" PublicKey="" PrivateKey="" Height="30px" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />

Code-behind(.aspx.cs)


protected void  btnSubmit_Click(object sender, EventArgs e)
    {
        recaptcha.Validate();
        if (recaptcha.IsValid)
        {
              if (Page.IsValid)
             {
                   lblResult.Text = "Captcha sucessfull!";
                   lblResult.ForeColor = System.Drawing.Color.Green;
             }
             else
            {
                 lblResult.Text = "Incorrect";
                 lblResult.ForeColor = System.Drawing.Color.Red;
             }
         }
    }

When I entered correct captcha text and pressed submit button following was the output:
 When I entered incorrect captcha text and pressed submit button following was the output:







  1. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:










  2. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:













  3. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  4. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:










  5. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  6. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:










  7. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  8. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:










  9. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  10. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:












  11. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  12. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:







  13. Read more: http://www.techartifact.com/blogs/2011/01/recaptcha-free-captcha-service-for-asp-net.html#ixzz1jsTc1Pwi




  14. Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.









  15. Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:






  16. 2 comments: