Original source: http://www.9cbs.net/develop/read_article.asp? ID = 22618 The above is the original source, it is VB version! In the comment, CWBBOY gave the C # code to refer to the code, practiced! OK Record! Generate the gif.aspx file of the picture! Need to introduce two namespaces! ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----- START -------------------------------------------------------------------------------------------------------------------------------------------------------------- --using system.drawing; using system.drawing.Imaging; private void page_load (object sender, system.eventargs e) {// Place user code here to initialize page // rNDNUM is a custom function string vnum = rNDNUM (4); // The number 4 represents the 4-bit verification string! Session ["vnum"] = vnum; validatecode (vnum);} // Generate image function private void value "{int Gheight = (int)); // Gheight is a picture width, according to Character length automatically change image width system.drawing.bitmap img = new system.drawing.bitmap (GHEIGHT, 20); graphics g = graphics.fromImage (img); g.drawstring (vnum, new system.drawing.font ("Arial ", 10), new system.drawing.Solidbrush (Color.RED), 3, 3); // Draw strings in the rectangular shape (string, font, brush color, top left x. Y) system.io.MemoryStream MS = new system.io.MemoryStream (); img.save (ms, system.drawing.image.imageformat.png); response.clearcontent (); // Need to output image information To modify http head Response.contentType = " Image / PNG "; response.binaryWrite (ms.toarray ()); g.dispose (); img.dispose (); response.end ();} // Generate random number in Vchar array randomly extracted /// Alphabetical Case Case PUBLIC STRING RNDNUM (INT VCODENUM) {String Vchar = "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, i, j, k, l, m, n, o, p, q, r, s, t, u, w, x, y, z "; string [] vcarray = vchar.split (',') String vnum = ""; // Since the string is very short, there is no StringBuilder INT TEMP = -1; // Record the last random value, try to avoid production Same random number
// With a simple algorithm to ensure different random rand = new random (); for (int i = 1; i Hover.Manage.CheckLogin obj = new Hover.Manage.CheckLogin (); string name = username.Text; string password = FormsAuthentication.HashPasswordForStoringInConfigFile (pass.Text.ToString (), "md5");! If (obj.checklogin ( Name, Password)) {response.redirect ("../ error.aspx? Action = errorlogin"); response.end (); return;} else {session.add ("adminName", name); session.add ( "adminss", password); response.redirect ("default.aspx"); response.end (); return;}} else {response.write ("