C # implement the verification code function,

Source: Internet
Author: User

C # implement the verification code function,

I. Verification Code Introduction
The verification code function is generally used to prevent batch registration. Many websites use the verification code technology to prevent users from automatically registering, logging on, And bumping through robots. The so-called verification code is to generate an image with a random string of numbers, letters, symbols, or characters, and add some interference pixels to the image to prevent OCR ), the user can identify the verification code information with the naked eye, and enter a form to submit the website for verification. A function can be used only after the verification is successful.

Common verification codes are as follows:
1. Pure Digital verification code, generally four random numbers;
2. digit + letter verification code, generally from number (0 ~ 9) and letters (~ Z and ~ Z;
3. Chinese Character verification code, which is relatively rare and complicated to implement, can still be seen on many websites;

Ii. Verification Code Implementation
1. Implementation of pure digital verification Codes
The implementation of a pure digital verification code is relatively simple, and can be achieved through the following two methods

/// <Summary> /// digital verification code /// </summary> /// <param name = "codeCount"> Number of digits of the Verification Code 'n' </param>/ // <returns> returns the 'N'-bit verification code String </returns> private static String GetRandomint (int codeCount) {Random random = new Random (); StringBuilder sbmin = new StringBuilder (); StringBuilder sbmax = new StringBuilder (); for (int I = 0; I <codeCount; I ++) {sbmin. append ("1"); sbmax. append ("9");} return random. next (Convert. toInt32 (sbmin. toString (), Convert. toInt32 (sbmax. toString ())). toString ();}

2. Combination of digits and letters

The combination of letters and numbers is also relatively simple. You can generate uppercase and lowercase letters according to your own rules.

/// <Summary> /// generate the verification code string /// </summary> /// <param name = "codeLen"> Verification Code character length </param> /// <returns> return the verification code string </returns> private static string MakeCode (int codeLen) {if (codeLen <1) {return string. empty;} int number; StringBuilder sbCheckCode = new StringBuilder (); Random random = new Random (); for (int index = 0; index <codeLen; index ++) {number = random. next (); if (number % 2 = 0) {sbCheckCode. append (char) ('0' + (char) (number % 10); // generate number} else {sbCheckCode. append (char) ('A' + (char) (number % 26); // generate A letter} return sbCheckCode. toString ();}

3. generate an image stream

Principle: You can generate a verification code, and then convert the generated verification code into an image for output.

/// <Summary> /// obtain the verification code image stream /// </summary> /// <param name = "checkCode"> Verification code string </param> /// <returns> return verification code image stream </returns> public static MemoryStream CreateCodeImg (string checkCode) {if (string. isNullOrEmpty (checkCode) {return null;} Bitmap image = new Bitmap (int) Math. ceiling (checkCode. length * 12.5), 22); Graphics graphic = Graphics. fromImage (image); try {Random random = new Random (); graphic. clear (Color. white); int x1 = 0, y1 = 0, x2 = 0, y2 = 0; for (int index = 0; index <25; index ++) {x1 = random. next (image. width); x2 = random. next (image. width); y1 = random. next (image. height); y2 = random. next (image. height); graphic. drawLine (new Pen (Color. silver), x1, y1, x2, y2);} Font font = new Font ("Arial", 12, (FontStyle. bold | FontStyle. italic); System. drawing. drawing2D. linearGradientBrush brush = new System. drawing. drawing2D. linearGradientBrush (new Rectangle (0, 0, image. width, image. height), Color. red, Color. darkRed, 1.2f, true); graphic. drawString (checkCode, font, brush, 2, 2); int x = 0; int y = 0; // foreground noise of the picture to be painted for (int I = 0; I <100; I ++) {x = random. next (image. width); y = random. next (image. height); image. setPixel (x, y, Color. fromArgb (random. next ();} // draw the border line graphic of the image. drawRectangle (new Pen (Color. silver), 0, 0, image. width-1, image. height-1); // Save the image verification code as a Stream and return the System. IO. memoryStream MS = new System. IO. memoryStream (); image. save (MS, System. drawing. imaging. imageFormat. gif); return MS;} finally {graphic. dispose (); image. dispose ();}}
Call Method

Call in HttpHander ProcessRequest: pupublic void ProcessRequest (HttpContext context) {string code = MakeCode (5); context. response. clearContent (); context. response. contentType = "image/Gif"; MemoryStream MS = CreateCodeImg (code); if (null! = Ms) {context. Response. BinaryWrite (ms. ToArray ());}}


CC real name

The story of LULU and King Arthur and the real name Analysis of CC
According to a strong analysis on the Internet.
Although lancot appeared in the first season
But he never imagined it with Arthur.
Because it is the name of the body, I don't think much about it.

Now I saw R2. seeing the name of the Round Table knight, the king opened his eyes with a pair of geass.
Only then can we realize that the essence of ruuxiu is actually a variant of Arthur's story...
If this is true, the true name of c. c is clear ..

The introduction of the Royal Family Name "briannia" refers to a relatively old saying in Britain. The "British kings" One hundred and fifty years ago used the British annia, and this book refers to the story of King Arthur's round table knight, the number of Round Table Knights ranges from.
In this tutorial, the Round Table server has a minimum of 12

In the legend of King Arthur, lancelot is a knight who betrayed the king because he fell in love with the king.
And he is an orphan of a young father

Let's look at the name of zhuque Shu Mu.
Pivot means key or important.
Zhuque now seems to be no different from the species of birds that can survive the burning of death.
So: OK: zhumu zhuque is a young father who will betray with love as an excuse. It plays an important role in this film, and how can he play an undead role...

King Arthur disappeared after a duel with his son mordred (in fact, he died). The reason for the duel is that this son wants to gain a throne. Please note that, king Arthur knew that his son would have killed him shortly after his birth (a legend in the west) but did not kill him. Instead, he continued to raise him.

Ruuxiu's name is very interesting.
Japanese is written in Japanese.
However, the official western style is: Lelouch Lamperouge
Let's take a look at this sentence.
Le louche explains abnormal behavior in the eyes and greedy behavior in the eyes.
Lampe rouge is a red light or lamp.
The son who killed Arthur was named Mordred.
The split shows that Mord is related to death + Red
OK: Lu luxiu is an eye that emits abnormal red light and greedy character (every time I play tactics, I want to use all the methods, and the result is reversed by the enemy's strong role ), sending is spreading the message of death to the prince who targeted his father.

Kalian
The old surname "Red Moon" in Area 11 refers to ominous things. Normally, attackers like to mount the moon at night.
The last name of the empire is Stadtfield, which indicates the field of the municipal council.
Her name, Kallen, was directly translated into Karine or Hualien for reference by the translation team.
In fact, this word means that it is a verb to hold it tightly with claws.
Everyone should know the explanation of her body, that is, the spark of a huge explosion.

OK: So cailian is a very honorable and non-invasive entity in the empire. However, it is always carrying out ominous activities in the dark. It is a fire of character and is good at operating a body that can hold the enemy tightly with claws.

So what?
Name of c. c. As a key character
It will certainly be associated with her miserable situation.
And it must be in touch with Arthur's background.
Because c. c. once belonged to the holy kingdom of Britain and then escaped.
That is to say, Arthur got and lost things.
This is not a human thing for Arthur.
And it can be related to the letter C.

Then only Arthur's first sword is Calibur.
The other name is Sword of the Stone before King Arthur gets it.
Later, it was broken in a duel that does not conform to the spirit of the server guard.

Caliburia is highly likely to become a personal name.
Considering that c. c. is a girl, it may be changed
Caliburian or Clirburess
Because C. C.'s real name is five syllables (11 episodes in the first season)
And... the remaining full text>

CC real name

The story of LULU and King Arthur and the real name Analysis of CC
According to a strong analysis on the Internet.
Although lancot appeared in the first season
But he never imagined it with Arthur.
Because it is the name of the body, I don't think much about it.

Now I saw R2. seeing the name of the Round Table knight, the king opened his eyes with a pair of geass.
Only then can we realize that the essence of ruuxiu is actually a variant of Arthur's story...
If this is true, the true name of c. c is clear ..

The introduction of the Royal Family Name "briannia" refers to a relatively old saying in Britain. The "British kings" One hundred and fifty years ago used the British annia, and this book refers to the story of King Arthur's round table knight, the number of Round Table Knights ranges from.
In this tutorial, the Round Table server has a minimum of 12

In the legend of King Arthur, lancelot is a knight who betrayed the king because he fell in love with the king.
And he is an orphan of a young father

Let's look at the name of zhuque Shu Mu.
Pivot means key or important.
Zhuque now seems to be no different from the species of birds that can survive the burning of death.
So: OK: zhumu zhuque is a young father who will betray with love as an excuse. It plays an important role in this film, and how can he play an undead role...

King Arthur disappeared after a duel with his son mordred (in fact, he died). The reason for the duel is that this son wants to gain a throne. Please note that, king Arthur knew that his son would have killed him shortly after his birth (a legend in the west) but did not kill him. Instead, he continued to raise him.

Ruuxiu's name is very interesting.
Japanese is written in Japanese.
However, the official western style is: Lelouch Lamperouge
Let's take a look at this sentence.
Le louche explains abnormal behavior in the eyes and greedy behavior in the eyes.
Lampe rouge is a red light or lamp.
The son who killed Arthur was named Mordred.
The split shows that Mord is related to death + Red
OK: Lu luxiu is an eye that emits abnormal red light and greedy character (every time I play tactics, I want to use all the methods, and the result is reversed by the enemy's strong role ), sending is spreading the message of death to the prince who targeted his father.

Kalian
The old surname "Red Moon" in Area 11 refers to ominous things. Normally, attackers like to mount the moon at night.
The last name of the empire is Stadtfield, which indicates the field of the municipal council.
Her name, Kallen, was directly translated into Karine or Hualien for reference by the translation team.
In fact, this word means that it is a verb to hold it tightly with claws.
Everyone should know the explanation of her body, that is, the spark of a huge explosion.

OK: So cailian is a very honorable and non-invasive entity in the empire. However, it is always carrying out ominous activities in the dark. It is a fire of character and is good at operating a body that can hold the enemy tightly with claws.

So what?
Name of c. c. As a key character
It will certainly be associated with her miserable situation.
And it must be in touch with Arthur's background.
Because c. c. once belonged to the holy kingdom of Britain and then escaped.
That is to say, Arthur got and lost things.
This is not a human thing for Arthur.
And it can be related to the letter C.

Then only Arthur's first sword is Calibur.
The other name is Sword of the Stone before King Arthur gets it.
Later, it was broken in a duel that does not conform to the spirit of the server guard.

Caliburia is highly likely to become a personal name.
Considering that c. c. is a girl, it may be changed
Caliburian or Clirburess
Because C. C.'s real name is five syllables (11 episodes in the first season)
And... the remaining full text>

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.