reCAPTCHA : Add free captcha to your project / website

reCAPTCHA is a free CAPTCHA service that helps to stop spam & give security to site.
reCAPTCHA is a Web service. A CAPTCHA is a program that can tell whether its user is a human or a computer.

It is completely free to use in your website / project.To use it
Just Follow the steps:-
1.  Register for a reCaptcha key : Free Register / Signup at recaptcha to create/get key ((private,public key) or API key).After signup enter you website name at "Domain" box to create key ,if  you want to use it in your local server project then write "localhost" at "Domain" box. just as below :

2.  Download reCaptcha dll file for ASP.NET : Download the dll file from here.After file downloaded add to your project reference .

3.  Add reCaptcha on ASP.NET page : To add reCaptcha on your ASP.net page  first you have to
add below code at top of .aspx page to register reCaptcha dll file:
<%@ register tagprefix="recaptcha" 
namespace="Recaptcha" 
assembly="Recaptcha" %>
Then insert the reCAPTCHA control inside of the "form" tag:


Enter/use your reCapcha key(public key,private key)at publickey & private key
respectivly in above code.

4.  Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission).
The Following Example show you overally , how you use reCAPTCHA:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="RecaptchaPage.aspx.cs" Inherits="ContosoUniversity.RecaptchaPage" %>
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
</body> </html>
In your code-behind or .cs file add code as below :
public partial class RecaptchaPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
          lblResult.Text = "You Got It!";
          lblResult.ForeColor = System.Drawing.Color.Green;
        }
        else
        {
          lblResult.Text = "Incorrect";
          lblResult.ForeColor = System.Drawing.Color.Red;
        }
    }
}
When you enter valid captcha & click submit button ,it shows message as below :

When you enter invalid captcha click submit button , it shows message as below :

You also can change reCaptcha theme by changing Theme="themename" in reCAPTCHA
control.Use ("white","Red","blackglass","clean" in place of "themename") as
below :

0 comments: (+add yours?)

Post a Comment