Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Recaptcha

0.00/5 (No votes)
22 Oct 2013 1  
Recaptcha:Captcha keeps the spammer away from our site. There is Lot of captcha conrols available for asp.net and few may not work on postback.

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

Recaptcha:

Captcha keeps the spammer away from our site. There is Lot of captcha conrols available for asp.net and few may not work on postback. Google has released a captcha control as “recaptcha” for asp.net developer and its easy plug and more secure and customizable and its Totally free all you need is gmail id.


To Use “recaptcha” Control on your website you must register your site and get an API Key.


Visit the link https://www.google.com/recaptcha/admin/create


After registering your site Google will provide the Two Keys
•    Public Key and
•    Private Key 


To use recaptcha with ASP.NET, you MUST download the DLL file


http://code.google.com/p/recaptcha/downloads/detail?name=recaptcha-dotnet-1.0.5.0-binary.zip&can=2&q=label%3Aaspnetlib-Latest


Now Download folder contains a file Recaptcha.dll add the file to bin folder of your project and reference dll to your project.
Now create a blank aspx page and add header to the page

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

<recaptcha:RecaptchaControl ID="recap" PublicKey="Yourpublic Key" PrivateKey="Your Private Key" runat="server" />

To validate this recaptcha add few below line of code in button click event 

            if (Page.IsValid == true )
            {
                Label1.Text = "Capacta Right";
            }
            else
            {
                Label1.Text = "Wrong";
            }

Customize:
           You can set Theme for  recaptcha control.By Default red theme is set.
There are Four themes


<recaptcha:RecaptchaControl ID="recap" PublicKey="Yourpublic Key" PrivateKey="Your Private Key" runat="server" Theme="clean" /> 

 Clean theme look more professional than other themes.


Custom Themes and Size:
             We can Create our custom theme and resize the recaptcha. To do First set theme property as custom.

<recaptcha:RecaptchaControl ID="recap" PublicKey="Yourpublic Key" PrivateKey="Your Private Key" runat="server" Theme="custom" CustomThemeWidget="recaptcha_widget"   /> 

Captcha has Image,textbox,Refresh button,Audio Captcha and Help Buttons and we can remove any these button as per our need to do so paste  the script in anywhere in design source.

   <div id="recaptcha_widget" style=" display : none">
   < div id ="recaptcha_image"></div>
   <div class="recaptcha_only_if_incorrect_sol" style=" color : red"> Incorrectplease try again </div>
   <span class="recaptcha_only_if_image"> Enter thewords above: </span>
   <span class="recaptcha_only_if_audio"> Enter thenumbers you hear: </span>
   <input type="text" id="recaptcha_response_field" name="recaptcha_response_field" />
   <div><a href="javascript:Recaptcha.reload()"> Getanother CAPTCHA </a></div>
   <div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"> Getan audio CAPTCHA </a></div >

   <div class="recaptcha_only_if_audio"><a href="javascript:Recaptcha.switch_type('image')"> Getan image CAPTCHA </ a ></ div >
   <div><a href="javascript:Recaptcha.showhelp()"> Help </a></div>
  </div>
  <script type ="text/javascript"
    src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
  </script >
  <noscript>
   <iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
        height="300" width="500" frameborder="0"></iframe><br>
   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
   </textarea>
   <input type="hidden" name ="recaptcha_response_field"
        value="manual_challenge">
  </noscript>

 Two thing need to be noticed while you paste the above code


1. Div Tag must have same ID as CustomThemeWidget="recaptcha_widget"
2. Replace your public key in the above snippets.(Inside the Script Tag)

Now Custom captcha look like below.

 

 

 

We can remove the “Get another captcha” or “Get an Audio captcha” or “help”.

Now we try to remove the Get audio captcha and Help Link.
To do so, Just remove the below two lines from above snippets
 

<div class="recaptcha_only_if_image"><a href="javascript:Recaptcha.switch_type('audio')"> Getan audio CAPTCHA </a></div >
<div><a href="javascript:Recaptcha.showhelp()"> Help </a></div>

 To change background color define background color   in css class for ID “recaptcha_widget”

<div id="recaptcha_widget" style="background-color:#f7f7f7;"> 
 To change the width:
<div id="recaptcha_widget" style="background-color:#f7f7f7;width:300px;">

and width should be minimum 300px.

Sites that use recaptcha is facebook,wikipedia,tinypic...

 

 

 

 

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here