A random verification string is generated when logging in! !

xiaoxiao2021-03-06  80

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 {///

/// WebForm4 summary description. /// public class Webform4: system.Web.ui.page {private void page_load (Object sender, system.eventargs e) {// A user program code is initialized to initialize web page // rNDNUM is a self Define function string vnum = rNDNUM (6); // Here the number 6 represents 6 bits of random strings! Session ["VNUM"] = vnum; validatecode (vnum);

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);} ///

/// This is a way to design tool support - Do not use the program code editor to modify the /// this method. /// private () {this.load = new system.eventhandler (this.page_load);

} #ENDREGON}} Verification Password File Private Void Button1_click (Object Sender, System.EventArgs E) {String Vnum; vnum = session ["vnum"]. TOSTRING (); if (this.txtvc.text! = Vnum) {response.write ("