This is a simple to use Audio Captcha made for ASP.NET MVC
- jquery
- bootstrap
- SessionState must be enabled (default is)
- Copying 'libmp3lame.32.dll' and 'libmp3lame.32.dll' in bin project (included in nuget package)
-
Add a reference to 'Pigi.Captcha.dll' to your project.
or install using nuget package manager :
Install-Package Pigi.Captcha.Mvc
-
add
using Pigi.Captcha
namespace to top of global.asax.cs Add Captcha httphandlers to route table by calling this method.RouteTable.Routes.AddPigiCaptchaHandlers();
***Note*** call to this method should be before calling toRouteConfig.RegisterRoutes(RouteTable.Routes);
- Make sure that you added packages 'NAudio' and 'NAudio.Lame' to your project and see if these two dlls are included in bin folder : 'libmp3lame.64.dll' 'libmp3lame.32.dll' They are used for audio compression purpose.
-
Add
@using Pigi.Captcha
to the top of your view.cshtml -
Add this helper method to generate Audio Captcha.
@Html.Captcha(new CaptchaSettings { Id = "c1" })
you can also customize more by setting 'CaptchaSettings' object properties, like image size, captcha style, enabling captcha user input... -
And then verify captcha in an action like this
[HttpPost] public ActionResult Index(string c1) { var isCaptcha1Valid = CaptchaManager.ValidateCurrentCaptcha("c1", c1);
ViewBag.c1 = isCaptcha1Valid; return View(); }