If you've incorporated CAPTCHA into an ASP.NET MVC application, did you use an external CAPTCHA library of some kind? If so, would you recommend it and why?
-
possible duplicate of [How to Use Captcha in asp.net mvc](http://stackoverflow.com/questions/2286688/how-to-use-captcha-in-asp-net-mvc) – Oliver Feb 18 '11 at 11:34
3 Answers
- do you use nuget? if you don't, right click on the reference section of your project and choose ad library package reference
- get to the online tab, and install Microsoft Web Helpers dll
- In this refrence, you will find a very handy helper which is ReCaptcha.GetHtml
you can use it on your view as like below;
@ReCaptcha.GetHtml(ConfigurationManager.AppSettings["recaptcha-public-key"], "white")
I keep my recaptcah keys inside web.config so I used ConfigurationManager.AppSettings to reach them. You can get your own public and private keys from http://www.google.com/recaptcha
In your controller, it is very easy to handle the legitimate call like below;
if (ReCaptcha.Validate(ConfigurationManager.AppSettings["recaptcha-private-key"])) {
//the call is legitimate
} else {
// the call is not legitimate
}
I hope this helps.
Update 1 Uppps. don't forget to put the private and public keys inside you _ViewStart.cshtml file like below;
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ReCaptcha.PrivateKey = ConfigurationManager.AppSettings["recaptcha-private-key"];
ReCaptcha.PublicKey = ConfigurationManager.AppSettings["recaptcha-public-key"];
}

- 57,477
- 67
- 243
- 335
For an easy customisable one I would use: http://xcaptcha.codeplex.com/
For a standard complex one use: http://mvcrecaptcha.codeplex.com/

- 6,339
- 6
- 27
- 34
I agree with Lee Smit. I would recommend using MVCRecaptcha (https://mvcrecaptcha.codeplex.com/).
You can also download the package from Nuget, however, make SURE that you don't download the other Recaptcha packages that are available - you should specifically download MVC recaptcha.
Then follow the rest of the instructions on the MVC recaptcha codeplex site to get up and running.