Image analysis of several common verification codes on the Internet

Source: Internet
Author: User
Tags bmp image

Some common verification codes:

Function Analysis:
Common Verification Code features:
1. display content
The display content is generally a number or number + character, and more abnormal, the display content is random Chinese characters.
For how to randomly generate Chinese characters, see:
Basic Principles of generating random Chinese Character verification codes with C #
Http://wulei8899.cnblogs.com/archive/2005/06/29/183200.html

2. content display
The content shows that there are many common methods:
2.1 display the content in an uncommon font,
2.2 random font tilt display
2.3 different colors are displayed randomly for each word
2.4 The content is randomly displayed in different locations.
2.5 text uses gradient color, the same word has several colors.

3. Background display
Common background display solutions:
3.1. Use interference lines. Several interference lines are displayed at random. The color of these lines is similar to that of the font.
3.2. Interference points, followed by several random interference points. The color of these points is similar to that of the font.
3.3 interference color block, followed by a random Color Block for interference

Common open-source verification code generationCode

:
Related Articles: Asp.net Verification Code (C #)
Http://blog.csdn.net/SW515/archive/2005/02/03/279364.aspx
I personally like this among these open-source verification codes. The verification code will not be complex and cannot be identified by users, and it is quite difficult to judge the program.

RelatedArticle: ASP generates a color variable length Verification CodeProgram
Http://www.codefans.com/ArticleView/Article_6728.html

ASP. NET Dynamic generation of Verification Code
Http://sleeping.cnblogs.com/archive/2005/12/19/299980.html

Color verification codes like Dev-club
Http://www.blueidea.com/tech/program/2003/709.asp

C # color Verification Code
Http://www.codefans.com/ArticleView/Article_6745.html

Verifycode (ASP), GIF Verification Code Generation Technology
Http://www.codefans.com/ArticleView/Article_6735.html

Region implements a verification code class
Http://www.innerv.com/blogview.asp? Logid = 509 & cateid = 5

How to dynamically generate a verification code in Asp.net
Http://www.dwww.cn/new/2005911154522249.html

256-color BMP image verification code recognition script
Http://www.51cto.com/html/2005/1101/10438.htm

Qq verification code recognitionSource code(C #/net1.1)
Http://www.intodigi.com/Net/Website/Program/NET/12082.html

Example:

/* Copyright All (c) 2005 zhongfeng, http://blog.csdn.net/SW515 */
Public class validatecode: system. Web. UI. Page
{
Private void page_load (Object sender, system. eventargs E)
{
This. createcheckcodeimage (generatecheckcode ());
}

# Code generated by region web Form Designer
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}

/// <Summary>
/// The designer supports the required methods-do not use the code editor to modify
/// Content of this method.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion

Private string generatecheckcode ()
{
Int number;
Char code;
String checkcode = string. empty;

System. Random random = new random ();

For (INT I = 0; I <5; I ++)
{
Number = random. Next ();

If (Number % 2 = 0)
Code = (char) ('0' + (char) (Number % 10 ));
Else
Code = (char) ('A' + (char) (Number % 26 ));

Checkcode + = code. tostring ();
}

Response. Cookies. Add (New httpcookie ("checkcode", checkcode ));

Return checkcode;
}

Private void createcheckcodeimage (string checkcode)
{
If (checkcode = NULL | checkcode. Trim () = string. Empty)
Return;

System. Drawing. bitmap image = new system. Drawing. Bitmap (INT) math. Ceiling (checkcode. length * 12.5), 22 );
Graphics G = graphics. fromimage (image );

Try
{
// Generate a random Generator
Random random = new random ();

// Clear the background color of the image
G. Clear (color. White );

// Draw the background noise line of the image
For (INT I = 0; I <25; I ++)
{
Int X1 = random. Next (image. width );
Int X2 = random. Next (image. width );
Int Y1 = random. Next (image. Height );
Int y2 = random. Next (image. Height );

G. drawline (new pen (color. Silver), X1, Y1, X2, Y2 );
}

Font font = new system. Drawing. Font ("Arial", 12, (system. Drawing. fontstyle. Bold | system. Drawing. fontstyle. italic ));
System. drawing. drawing2d. lineargradientbrush brush = new system. drawing. drawing2d. lineargradientbrush (New rectangle (0, 0, image. width, image. height), color. blue, color. darkred, 1.2f, true );
G. drawstring (checkcode, Font, brush, 2, 2 );

// Foreground noise of the image
For (INT I = 0; I <100; I ++)
{
Int x = random. Next (image. width );
Int y = random. Next (image. Height );

Image. setpixel (X, Y, color. fromargb (random. Next ()));
}

// Draw the border line of the image
G. drawrectangle (new pen (color. Silver), 0, 0, image. Width-1, image. Height-1 );

System. Io. memorystream MS = new system. Io. memorystream ();
Image. Save (MS, system. Drawing. imaging. imageformat. GIF );
Response. clearcontent ();
Response. contenttype = "image/GIF ";
Response. binarywrite (Ms. toarray ());
}
Finally
{
G. Dispose ();
Image. Dispose ();
}
}
}

Assume that the above verification code generator page is named: checkcode. aspx, use the "
Use the following code to determine the verification code in the event handling button on the logon page:

Private void btnlogin_click (Object sender, system. Web. UI. imageclickeventargs E)
{
If (request. Cookies ["checkcode"] = NULL)
{
Lblmessage. Text = "your browser settings have been disabled for cookies. You must set the options that allow the browser to use cookies before using the system. ";
Lblmessage. Visible = true;
Return;
}

If (string. Compare (request. Cookies ["checkcode"]. Value, txtcheckcode. Text, true )! = 0)
{
Lblmessage. Text = "Incorrect verification code. Enter the correct verification code. ";
Lblmessage. Visible = true;
Return;
}

// Other code
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.