Its a common requirement that we require a captcha to be integrated on our page. I would like to mention a free captcha service which can be implemented in integrated on websites.
What is reCaptcha?
which are required to integrate it into a ASP.NET page.
Steps to Integrate reCaptcha in ASP.NET
Markup:
Code-behind
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:
What is reCaptcha?
- reCAPTCHA is a free CAPTCHA service that helps to digitize books, newspapers and old time radio shows.
- It’s Free! Yep, reCAPTCHA is free.
- 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. - It’s Accessible. reCAPTCHA has an audio test that allows blind people to freely
navigate your site. - It’s Secure. Most other CAPTCHA implementations can be easily broken.
- It’s Popular. Over 100,000 sites use reCAPTCHA, including household names like Facebook, Ticketmaster, and Craigslist.
- Whenever uses input data in reCaptcha control, they actually help digitizing books.
which are required to integrate it into a ASP.NET page.
Steps to Integrate reCaptcha in ASP.NET
- 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.
- Download reCaptcha library for ASP.NET: Download the dll file from here. Also add the reference to the dll in the asp.net project.
- Add reCaptcha widget on ASP.NET page : Insert the reCAPTCHA control into the form you wish to protect by adding the following code snippets:
- At the top of the aspx page, insert this: 12
<%@ register
tagprefix="recaptcha" namespace="Recaptcha" assembly="Recaptcha" %>
- Then insert the reCAPTCHA control inside of the form tag: 12
<
recaptcha:recaptchacontrol
id
=
"recaptcha"
runat
=
"server"
publickey
=
"your_public_key"
privatekey
=
"your_private_key"
/>
- At the top of the aspx page, insert this:
- Make sure you use ASP.NET validation to validate your form (you should check Page.IsValid on submission).
Markup:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <%@ 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 >
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 = "Captcha sucessfull!" ; lblResult.ForeColor = System.Drawing.Color.Green; } else { lblResult.Text = "Incorrect" ; lblResult.ForeColor = System.Drawing.Color.Red; } } } |
When I entered incorrect captcha text and pressed submit button following was the output:
No comments:
Post a Comment