Click here to Skip to main content
13,201,452 members (75,379 online)
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 20 Mar 2009

SixPack Library -- CaptchaImage

, 20 Mar 2009
Rate this:
Please Sign up or sign in to vote.
SixPack Library tutorial on how to use the CaptchaImage class


This article is part of an on-going series of tutorials explaining how to use the SixPack library. In this example, we show how to use the CaptchaImage class to generate effective CAPTCHAs for your site.


About the SixPack Library

The SixPack rapid development library is a collection of classes for rapid development on the .NET/Mono platform. It is released under the Limited General Public License 2.1 (LGPL) and is available through Google code.

Using the Code

This is an example of using the CaptchaImage class in the SixPack library.

Typically, you would generate a random sequence of characters, store it in session, then use this class to serve the image from a handler.

On submit, you would then compare the value input by the user with the value in session.

Stating the obvious: do NOT use a parameter to pass the correct CAPTCHA value to the handler... that would make the CAPTCHA useless!

A not-so-obvious note: mono does not support the WarpPath method in System.Drawing that we use to scramble the text. The class works around this by distorting the image in other ways under Unix environments. This is not as effective as the Win32 method, unfortunately.

In future versions of the library, we might create another CaptchaImage class based on ImageMagick, so we can provide a consistent user experience on both platforms.

using System;
using SixPack.Drawing;
using System.Drawing;
using System.Drawing.Imaging;

namespace sixpackexamples
        class MainClass
                public static void Main(string[] args)
                        CaptchaImage captcha = new CaptchaImage
				("foo-bar", 300, 100, "Times New Roman");
                        captcha.BackgroundDark = TangoPalette.SkyBlue1;
                        captcha.BackgroundLight = TangoPalette.SkyBlue3;
                        captcha.ForegroundDark = TangoPalette.SkyBlue2;
                        captcha.ForegroundLight = TangoPalette.SkyBlue1;
                        captcha.FontStyle = FontStyle.Italic;
                        Image image = captcha.Generate();
                        Bitmap bitmap = new Bitmap(image);
                        bitmap.Save("foobar.png", ImageFormat.Png);                    

The result of this operation will be the following (under mono):



  • 20th March, 2009: Initial post


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Team Leader Trayport Ltd
United Kingdom United Kingdom
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralLink Broken Pin
thund3rstruck20-Mar-09 10:15
memberthund3rstruck20-Mar-09 10:15 
GeneralRe: Link Broken Pin
Ravi Bhavnani20-Mar-09 10:29
memberRavi Bhavnani20-Mar-09 10:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.171020.1 | Last Updated 20 Mar 2009
Article Copyright 2009 by sklivvz
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid