This project is read-only.

AIP Providers

Important: This documentation applies to 1.0 only. The 2.0 documentation is here

There are three kinds of providers used by AIP: text, bitmap and filter providers. The AIP library provides implementations of each so that you can immediately use the AIP web control in your websites.

Text Providers

Text providers are classes that derive from the DaveSexton.Web.Controls.Configuration.AutoInputProtectionTextProvider class, directly or indirectly. The purpose of a text provider is to generate random CAPTCHA text and validate the user's input.

A default text provider is required. Only one provider may be registered as the default using the defaultTextProvider attribute of the autoInputProtection element. If you do not define the autoInputProtection section in your web.config file then the basic English text provider will be used automatically.

For help creating a custom text provider, see How Do I create a custom AIP text provider?.

Configuration
Text providers are configured in the autoInputProtection configuration element using the textProviders collection element. For example:

<textProviders>
  <add name="a_text_provider"
       type="DaveSexton.Web.Controls.BasicEnglishAutoInputProtectionTextProvider, DaveSexton.AutoInputProtection"
       colors="Red,Green,Blue,Brown" fonts="Times New Roman,Arial,Lucida Sans" />
</textProviders>

The colors and fonts attributes are required for all text providers, regardless of the implementation.

Built-In Text Providers
There are two concrete implementations built-in to the AIP library: Abstract Base Class
Here is the interface of the base text provider class:

public abstract class AutoInputProtectionTextProvider : ProviderBase
{
  public bool CaseSensitiveComparison { get; set; }
  public int MaximumCharacters { get; set; }
  public int MinimumCharacters { get; set; }
  public int MinimumFontSize { get; set; }
  public int MaximumFontSize { get; set; }
  public IList<Color> Colors { get; set; }
  public IList<Font> Fonts { get; set; }

  protected AutoInputProtectionTextProvider() { }

  public virtual bool ValidateUserInput(string userText, string bitmapText);

  public abstract string GenerateRandomAutoInputProtectionText();
}

Bitmap Providers

Bitmap providers are classes that derive from the DaveSexton.Web.Controls.Configuration.AutoInputProtectionBitmapProvider class, directly or indirectly. The purpose of a bitmap provider is to create a class that derives from AutoInputProtectionBitmap, which will generate a bitmap from the specified Size and AutoInputProtectionTextProvider implementation.

A default bitmap provider is required. Only one provider may be registered as the default using the defaultBitmapProvider attribute of the autoInputProtection element. If you do not define the autoInputProtection section in your web.config file then the line-noise bitmap provider will be used automatically.

For help creating a custom bitmap provider, see How Do I create a custom AIP bitmap provider?.

Configuration
Bitmap providers are configured in the autoInputProtection configuration element using the bitmapProviders collection element. For example:

<bitmapProviders>
  <add name="a_bitmap_provider" 
       type="DaveSexton.Web.Controls.ResourceAutoInputProtectionBitmapProvider, DaveSexton.AutoInputProtection" />
</bitmapProviders>

There are no required attributes other than name and type.

Built-In Bitmap Providers
There are two concrete implementations and a derived abstract base class built-in to the AIP library: Abstract Base Class
Here is the interface of the base bitmap provider class:

public abstract class AutoInputProtectionBitmapProvider : ProviderBase
{
  protected AutoInputProtectionBitmapProvider();

  public static string ChooseRandomName(IList<string> names);
  public static string ChooseRandomName(string[] names);

  public abstract AutoInputProtectionBitmap GenerateAutoInputProtectionBitmap(
    string name, Size size, AutoInputProtectionTextProvider textProvider);
  public abstract AutoInputProtectionBitmap GenerateRandomAutoInputProtectionBitmap(
    Size size, AutoInputProtectionTextProvider textProvider);
}

Filter Providers

Filter providers are classes that derive from the DaveSexton.Web.Controls.Configuration.AutoInputProtectionFilterProvider class, directly or indirectly. Filters are optional providers that will modify the image generated by a bitmap provider. Filter providers are used to increase the randomization of AIP or to make the generated images aesthetically pleasing in the context of your website. They are especially useful for applying common effects to third-party bitmap providers. Filters are purely graphical and do not have any reference to the validation text.

For help creating a custom filter provider, see How Do I create a custom AIP filter provider?.

Configuration
Filter providers are configured in the autoInputProtection configuration element using the filters collection element. For example:

<filters>
  <add name="horizontalbars" 
       type="DaveSexton.Web.Controls.TranslucentBarsOverlayAutoInputProtectionFilterProvider, DaveSexton.AutoInputProtection"
       colors="Orange,Yellow,Fuchsia" />
</filters>

Any number of filters may be applied. The order in which the filters are processed is the order in which they are added to the filters element, top-down, in your web.config file. All of the filters in the filters element are used; if you want to exclude a filter then you must remove it from the configuration.

The base filter provider has no required attributes other than name and type; however, the TranslucentBarsOverlayAutoInputProtectionFilterProvider class requires the colors attribute to be specified as well.

Built-In Filter Providers
There is currently only one concrete implementation built-in to the AIP library, but it's quite flexible and can be used multiple times on the same bitmap with different settings: Abstract Base Class
Here is the interface of the base filter provider class:

public abstract class AutoInputProtectionFilterProvider : ProviderBase, IDisposable
{
  public abstract bool CanPreProcess { get; }
  public abstract bool CanPostProcess { get; }

  protected bool IsDisposed;

  protected AutoInputProtectionFilterProvider();

  public abstract void PreProcess(Graphics graphics, Size bitmapSize);
  public abstract void PostProcess(Graphics graphics, Size bitmapSize);

  // canonical disposal pattern
  public void Dispose();
  protected virtual void Dispose(bool disposing);
  ~AutoInputProtectionFilterProvider();  // finalizer
}

Modes of Operation
There are two modes in which a filter provider may be applied: Pre-process and Post-process. Filters may provide one or both modes.

Pre-Process
A pre-process filter applies to the background image before the composite image has been created. The composite image is the bitmap's background with the validation text rendered on top. The background image is referred to as a Surface Bitmap and it's provided by an AutoInputProtectionBitmap implementation, which is provided by the AutoInputProtectionBitmapProvider implementation that is configured as the default bitmap provider.

Post-Process
A post-process filter applies to the composite image, which includes the pre-rendered validation text.

Last edited Apr 2, 2008 at 1:34 PM by davedev, version 4

Comments

No comments yet.