Two .aspx files, one for generating pictures, the other for verifying. Images generated code files using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web .Ui.webcontrols; using system.web.ui.htmlcontrols;
Namespace csharpall {///
Private void validatecode (string vnum) {INT GHEIGHT = (int)); // Gheightl image width, automatically change image width system.drawing.bitmap img = new system.drawing.bitmap (GHEIGHT) according to character length , 20); Graphics g = graphics.fromImage (img); g.drawstring (vnum, new system.drawing.font ("arial", 10), new system.drawing.solidbrush (color.red), 3, 3) // In the rectangular control string (string, font, word break color, on the left X.- Y) system.io.MemoryStream ms = new system.io.MemoryStream (); img.save (ms, system.drawing. Imaging.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 ();} 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, J, K, L, M, N, P, Q, R, S, T, U, W, X, Y "; String [] vcarray = vchar.split ( ','); String vnum = ""; // Since the string is very short, it is not necessary to use the stringbuilder INT TEMP = -1;
// With a random algorithm to ensure a random different random rand = new random (); for (int i = 1; i #REGION Web Form Design Tool Produced Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This is the call required for the ASP.NET Web Form Design tool. // InitializationComponent (); base.onit (e);} /// } #ENDREGON}} Verification Password File