The verification technology in Asp.net is as follows,
Checkcode. aspx
Using system;
Using system. Data;
Using system. configuration;
Using system. collections;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using system. Web. UI. htmlcontrols;
Using system. IO;
Using system. drawing;
Using system. Drawing. imaging;
Using system. Drawing. drawing2d;
Public partial class admin_checkcode: system. Web. UI. Page
{
Private bitmap validateimage;
Private graphics g;
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
String vnum = makevalidatecode ();
Session ["vnum"] = vnum;
Validatecode (vnum );
}
}
Public void validatecode (string vnum)
{
Validateimage = new Bitmap (60, 15, pixelformat. format24bpprgb );
G = graphics. fromimage (validateimage );
G. fillrectangle (New lineargradientbrush (new point (0, 0), new point (110, 20), color. fromargb (1, 240,255,255,255), color. fromargb (240,255,255,255), 0, 0,200,200 );
G. drawstring (vnum, new font ("Arial", 11), new solidbrush (color. Red), new pointf (6, 0 ));
G. Save ();
Memorystream MS = new memorystream ();
Validateimage. Save (MS, system. Drawing. imaging. imageformat. GIF );
Response. clearcontent ();
Response. contenttype = "image/BMP ";
Response. binarywrite (Ms. toarray ());
Response. End ();
}
String makevalidatecode ()
{
Char [] S = new char [] {'0', '1', '2', '3', '4', '5', '6 ', '7', '8', '9', 'A'
, 'B', 'C', 'D', 'E', 'E', 'F', 'G', 'h', 'I', 'J', 'k ', 'l', 'M', 'n', 'O', 'P', 'Q'
, 'R', 's', 't', 'U', 'V', 'w', 'x', 'y', 'z ', 'A', 'B', 'C', 'D', 'E', 'E', 'F', 'G'
, 'H', 'I', 'J', 'k', 'l', 'M', 'n', 'O', 'P', 'Q ', 'R', 's', 't', 'U', 'V', 'W'
, 'X', 'y', 'z '};
String num = "";
Random r = new random ();
For (INT I = 0; I <4; I ++)
{
Num + = s [R. Next (0, S. Length)]. tostring ();
}
Return num;
}
}
In the login. aspx foreground application:
In login. aspx. CS, use if (textbox1.text! = Session ["vnum"]. tostring (). tolower (): Is the verification entered by the customer correct.