Login verification code and login verification code

Source: Internet
Author: User

Login verification code and login verification code

Now, the login verification code is an indispensable verification on the login interface. Just like when I was at school, there should still be many students who only know that it is for security reasons. Why should I add the verification code? Can we see the verification code on the interface when logging on? What does this mean? I thought so silly. In fact, this verification code does not prevent the naked eye from cracking personal login accounts or malicious registration through "program machines", so as to prevent network hackers from obtaining relevant information, affecting network order and conducting illegal operations. User names and passwords on the login interface or registration interface may have format requirements. Hackers can write related programs according to the format requirements to generate login names and passwords in the correct format, if the verification code is saved to the server through session, it increases the difficulty of hacker cracking (if the server security level is high enough ), because the "machine" cannot see the verification code on the client as a human.

 

 

 

Code with a random verification code:

String chkCode = string. Empty;

// Color list for verification code, noise, and noise

Color [] color = {Color. Black, Color. Red, Color. Blue, Color. Green, Color. Brown, Color. Brown, Color. DarkBlue };

// Font list for verification code

String [] font = {"Gungsuh "};

// The Character Set of the Verification Code. Some confusing characters are removed.

Char [] character = {'2', '3', '4', '5', '6', '8', '9', 'A ', 'B', 'C', 'D', 'E', 'F', 'G', 'h', 'J', 'k', 'l ', 'M', 'n', 'P', 'R','s, 't', 'w', 'x', 'y '}; random rnd = new Random ();

// Generate a verification code string

For (int I = 0; I <4; I ++) {chkCode + = character [rnd. next (character. length)];} Bitmap bmp = new Bitmap (100, 40); Graphics g = Graphics. fromImage (bmp); g. clear (Color. white );

// Draw the verification code string

For (int I = 0; I <chkCode. length; I ++) {string fnt = font [rnd. next (font. length)]; Font ft = new Font (fnt, 22); Color clr = color [rnd. next (color. length)]; g. drawString (chkCode [I]. toString (), ft, new SolidBrush (clr), (float) I * 20 + 8, (float) 8 );}

// Clear the output cache of this page and set no cache for this page

Response. buffer = true; Response. expiresAbsolute = System. dateTime. now. addMilliseconds (0); Response. expires = 0; Response. cacheControl = "no-cache"; Response. appendHeader ("Pragma", "No-Cache ");

// Write the verification code image to the memory stream and output it in "image/Png" Format

MemoryStream MS = new MemoryStream ();

Try {bmp. Save (MS, ImageFormat. Png );

Session ["CheckCode"] = chkCode; Response. ClearContent ();

Response. ContentType = "image/Png"; Response. BinaryWrite (ms. ToArray ();} finally {

// Explicitly release resources

Bmp. Dispose ();

G. Dispose ();}

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.