Verification code creation

Source: Internet
Author: User
The project was completed in the early stage and started to work on the background. The pressure was lower and more time was needed to study new things.

The verification code is not a new thing. I never figured out what was going on. I used it when I used GDI the other day.

Background of the login pageCode, Use sleep to set the refresh latency

Private   Void Page_load ( Object Sender, system. eventargs E)
{
If ( ! This . Ispostback)
{
System. Threading. thread. Sleep ( 1000 );
Char [] Source = ( " Abcdefghijklmnopqrstuvwxyz1234567890 " ). Tochararray ();
String Code =   "" ;
Random RND =   New Random ();
For ( Int I = 0 ; I <   4 ; I ++ )
Code + = Source [RND. Next (source. Length - 1 )];
Session [ " Code " ] = Code;
}
}

Login verification Private   Void Btnlogin_click ( Object Sender, system. eventargs E)
{
If (Txtcode. Text. tolower () ! = Session [ " Code " ]. Tostring (). tolower ())
{
Response. Write ( " <SCRIPT> alert (\ " Incorrect verification code \ " ) </SCRIPT> " );
Response. Write ( " <SCRIPT> window. navigate (\ " Index. aspx \ " ) </SCRIPT> " );
Return;
}
If (Txtusername. Text =   " Username "   && Txtpassword. Text =   " Password " )
{
Session [ " Username " ] = Txtusername. text;
Response. Redirect ( " Next Page " );
}
Response. Write ( " <SCRIPT> alert (\ " Incorrect password \ " ) </SCRIPT> " );
Response. Write ( " <SCRIPT> window. navigate (\ " Index. aspx \ " ) </SCRIPT> " );
}

The front-end still uses an IMG Server Object URL as code. aspx
Code. aspx. CS:

Private   Void Page_load ( Object Sender, system. eventargs E)
{
If (Session [ " Code " ]. Tostring () ! = "" )
{
Bitmap BM =   New Bitmap ( 60 , 30 );
Graphics g = Graphics. fromimage (BM );
G. drawstring (session [ " Code " ]. Tostring (), New System. Drawing. Font ( " " , 20 ), New Solidbrush (color. whitesmoke ), 0 , 0 );
BM. Save (response. outputstream, system. Drawing. imaging. imageformat. GIF );
}
}

OK.

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.