Verification Code Applet

Source: Internet
Author: User

Using System;
Using System. Collections;
Using System. Configuration;
Using System. Data;
Using System. Linq;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. HtmlControls;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Xml. Linq;
Using System. Drawing;

Namespace SessionCode
{
Public partial class checkimage: System. Web. UI. Page
{
/// <Summary>
/// Verification Code Generation Program
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Protected void Page_Load (object sender, EventArgs e)
{
GetCode ();
}

// Generate code
Protected void GetCode ()
{
System. Random rand = new Random ();
Int len = 4; // set the verification code length here. I defined it as 4. Recently, I have seen random numbers of 4, 5, and 6 characters on the Internet. Write a random function here.
Char [] chars = "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ". ToCharArray ();
System. Text. StringBuilder myStr = new System. Text. StringBuilder ();

For (int iCount = 0; iCount <len; iCount ++)
{
MyStr. Append (chars [rand. Next (chars. Length)]);
}
String text = myStr. ToString ();
// Save the verification code to the session for other modules to use
Session ["code"] = text; // check whether the entered verification code is correct on your login page. if (txtCode. text = Session ["code"]) read the database correctly and retrieve the User/Password. An incorrect dialog box is displayed. Write by yourself
Size ImageSiz

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.