Product Example

I have updated my captcha image control. I believe it is sleeker and is overall better code wise.

Initiates an asynchronous call, and the returned result, will be a single image of alphanumeric characters. Image’s characters are presented in various font sizes and or (+/-) rotated in some degree.

This project offers the complete Visual Studio 2012 solution within a compressed zip file. Download the complete solution from CodePlex.

Shown below is the Captcha type which generates randomly selected characters and draws an image displaying those specific random characters.

Two files are involved rendering the Captcha image:

  • CaptchaControl.cs and CaptchaHandler.ashx
  • CaptchaControl.cs is a generic control rendering out an image and an Image Button. The rendered image’s ImageUrl property is dynamically set, and calls CaptchaHandler.ashx with an attached query string. The query string has a particular name/value pair specifying the particular Captcha characters.

CaptchaControl.cs generates and encodes characters appending the generated string to the rendering image’s query string.

CaptchaHandler.ashx returns a HTTPResponse bitmap and is displayed on the client side webpage.


CaptchaControl Class

Namespace: Captcha.Control
Assembly: CaptchaControl.dll

Syntax
public CaptchaControl : WebControl

Constructors

CaptchaControl(): base(HtmlTextWriterTag.Fieldset) Initializes a new instance of the CaptchaControl class


Properties

string RefreshButtonPath Absolute path to the Image Button’s image
string CaptchaHandlerUrl Absolute path to the Captcha Handler
int Minimum Minimum number of characters to be selected
int Maximum Maximum number of characters to be selected
int Overlap Amount of overlap between character placement.
int ImageWidth Captcha image’s width
int ImageHeight Captcha image’s height
string CharacterSet The character domain to select from. Default character set: ABDEGHMNQRTabdeghmnqr3456789#@&$%

CaptchaCharacters Class

Namespace: Captcha.Characters
Assembly: CaptchaControl.dll

Syntax
public CaptchaCharacters

Constructors

CaptchaCharacters() Initializes a new instance of the CaptchaCharacters class


Properties

string characterSet Get/Set, Sets characters domain, which characters should be included
string characters From the characterSet property, Gets/Sets randomly selected characters

Methods
GenerateCharacters(int, int) Creates a string of randomly selected ASCII characters where string length is specified from the two integer parameters.

EncodeCaptcha Class

Namespace: Captcha.Characters
Assembly: CaptchaControl.dll

Syntax
public EncodeCaptcha :  CaptchaCharacters

Constructors

EncodeCaptcha() Initializes a new instance of the EncodeCaptcha class
EncodeCaptcha(string key) Initializes a new instance of the EncodeCaptcha class with specified encoded key string value.


Properties

encodedKey Sets the encoded character string.


Methods

SaltKey() Encodes the randomly selected characters set in the characters property.

DrawCaptcha Class

Namespace: Captcha.Characters
Assembly: CaptchaControl.dll

Syntax
public DrawCaptcha :  EncodeCaptcha

Constructors

DrawCaptcha(int, int) Initializes a new instance of the DrawCaptcha class with specified integer width and integer height parameters.


Properties

int[] fontSizes Gets/Sets an array of integers specifying characters font size.
string[] families Gets/Sets an array of string specifying characters font family.
string[] colors Gets/Sets an array of string specifying characters font color.
string backgroundColor Gets/Sets images global background color
int overlap Gets/Sets amount of overlap between character placement.
int Width Get/Sets global Captcha image width
int Height Get/Sets global Captcha image height


Methods

Bitmap DrawCaptchaString() Draws randomly selected characters returning one bitmap with characters drawn.

Last edited Aug 13, 2012 at 5:33 PM by dedogs, version 4

Comments

No comments yet.