Compile & Install

For the compilation from the project's source code just open solution in Visual Studio 2010 and build it. No prerequisites required except .Net Framework 4.0.

Usage

  • Add reference to SimpleMvcCaptcha.dll in your ASP.NET MVC 3 project.
  • Copy "simplemvccaptcha.css" to folder where your CSS files are. Reference your view page to that file.
  • Implement special controller. Default value for controller's name is "CaptchaController", default action is "GetImage". You can redefine theese parameters in web.config (see Customization section below). In your GetImage action write this code:
        public FileContentResult GetImage(string id)
        {
            return File(CaptchaUtils.GetImage(id), "image/gif");
        }
  • In your .cshtml code write @Html.SimpleMvcCaptcha() to generate captcha's html. Put @using SimpleMvcCaptcha.Helper in the beginning of the file.
  • To validate user's input just write the code below:
        if (CaptchaUtils.Validate())
        {
                // Success
        }

Customization

There are several paremeters that can be customized in the web.config of an ASP.NET MVC 3 project, AppSettings section:
  • SimpleCaptchaMaxNumber - maximum number for captcha's expression operands. Default is 10.
  • SimpleCaptchaPlusOperationText - Text to substitute "+" operation. Default is "plus".
  • SimpleCaptchaMinusOperationText - Text to substitute "-" operation. Default is "minus".
  • SimpleCaptchaCaptchaController - Name of controller to get image. Default is "Captcha".
  • SimpleCaptchaCaptchaAction - Name of action to get image. Default is "GetImage".
  • SimpleCaptchaSecretKey - Secret key for string encription. Default is "123456".
  • SimpleCaptchaSalt - Salt for encription. Default is "12345678". Should be 8 characters long.
  • SimpleCaptchaMaxRandomLines - Max amount of captcha's random lines. Default is 5.
  • SimpleCaptchaWidth - Captcha's image width. Default is 100.
  • SimpleCaptchaHeight - Captcha's image height. Default is 20.
  • SimpleCaptchaFontName - Captcha's expression font name. Default is "Times New Roman".
  • SimpleCaptchaFontSize - Captcha's expression font size. Default is 14.
You can also customize html classes of div, image and input elements of the captcha. Div style is called "div.smc-captcha", input is "input.smc-input-result", image is "img.smc-img-captcha".

In version 1.2 you can also customize captcha in runtime using CaptchaParameters class:
Html.SimpleMvcCaptcha(new CaptchaParameters { ... })

Last edited Apr 20, 2012 at 12:28 PM by gmogelashvili, version 5

Comments

No comments yet.