views:

525

answers:

7

can any one tell me how to use captcha in asp.net mvc? is there any need to download any control for it?

Thank You.

A: 

check reCaptcha

Shoban
plz tell me another solution i want to use captch only not recaptcha.
mary
Why not recaptcha?.... Its is also a captcha.
Shoban
A: 

This blog post shows you how to do it.

Perpetualcoder
i tried form this blog but still image is not displying plz tell me another solution i want to use captch only not recaptcha.
mary
put some code sample in the question. Maybe we can help
Perpetualcoder
A: 

Another blog post: here at thenullreference.com

Greg Roberts
A: 

If you don't fancy writing your own Captcha (who does!) you can use a Captcha library, such as this:

http://www.coderjournal.com/2008/03/aspnet-mvc-captcha/

With a Captcha library, you add the dll to your project and use the Captcha API to display and validate the Captcha image and input.

Display a Captcha:

<label for="captcha">Enter <%= Html.CaptchaImage(50, 180) %> Below</label><br />
<%= Html.TextBox("captcha") %>

And then make sure you add the Captcha attribute to your method:

[CaptchaValidation("captcha")]

Recaptcha is just one option when it comes to Captcha's (in fact, it's the option selected by Stack Overflow!)

Sohnee
A: 

Check this Link

http://devlicio.us/blogs/derik_whittaker/archive/2008/12/02/using-recaptcha-with-asp-net-mvc.aspx

Will Definitely Help.

+3  A: 

Hoping it's not too late to put my two cents in...

Introducing MvcReCaptcha

I faced this exact same issue when trying to implement CAPTCHA validation on my first ASP.NET MVC site. After discovering many libraries, I found what seemed (and still seems) to be the most straightforward and efficient library: MvcReCaptcha. Since then, I have used this library for all of my ASP.NET MVC sites.

After you implement MvcReCaptcha, it securely generates a CAPTCHA on your view and provides a boolean value of whether the validation was successful to the action.


Instructions for Use

Here's how to implement it after downloading and referencing the MvcReCaptcha DLL from your project (instructions copied from MvcReCaptcha home page):

Using ReCaptcha with ASP.NET MVC:

It is now extremely easy to setup ReCaptcha on your Asp.Net MVC Website.

Signup for reCaptcha, http://recaptcha.net/whyrecaptcha.html

How to Use:

Step 1: Add your Public and Private key to your web.config file in appsettings section

<appSettings>
  <add key="ReCaptchaPrivateKey" value=" -- PRIVATE_KEY -- " />
  <add key="ReCaptchaPublicKey" value=" -- PUBLIC KEY -- " />
</appSettings>    

Step 2: Add new namespace to your web.config

<namespaces>
  <add namespace="MvcReCaptcha.Helpers"/>
</namespaces>

Step 3: Implement the logic in your view to actually render the Captcha control

<%= Html.GenerateCaptcha() %>

Step 4: Implement the Controller Action that will handle the form submission and Captcha validation

[CaptchaValidator]
[AcceptVerbs( HttpVerbs.Post )]
public ActionResult CreateComment( Int32 id, bool captchaValid )
{
  if (!captchaValid)
  {
      ModelState.AddModelError("_FORM", "You did not type the verification word correctly. Please try again.");
  }
  else
  {
      // If we got this far, something failed, redisplay form
      return View();
  }
}

Good luck!

Maxim Zaslavsky
A: 

Here is free MvcCaptcha library: http://www.smartsoftwarebits.com/mvccaptcha

And here is the article how to use it:http://www.smartsoftwarebits.com/mvccaptcha/91-mvccaptcha-getting-started-howto

Konstantin Nizhegorodov