PNG. aspx
Using system; using system. collections. generic; using system. drawing; using system. web; using system. web. ui; using system. web. UI. webcontrols; namespace maticsoft. web. admin {public partial class PNG: system. web. UI. page {protected void page_load (Object sender, eventargs e) {string checkcode = createrandomcode (4); Session ["checkcode"] = checkcode; createimage (checkcode );} private string createrandomcode (INT codecount) {// function: generate a random string allchar = "0123456789 characters"; char [] allchararray = allchar. tochararray (); string randomcode = ""; random Rand = new random (); For (INT I = 0; I <codecount; I ++) {int r = Rand. next (61); randomcode + = allchararray. getvalue (r);} return randomcode;} private void createimage (string checkcode) {// function for generating image Verification Code int iwidth = (INT) (checkcode. length * 11.5); system. drawing. bitmap image = new system. drawing. bitmap (iwidth, 20); graphics G = graphics. fromimage (image); font F = new system. drawing. font ("Arial", 10, system. drawing. fontstyle. bold); brush B = new system. drawing. solidbrush (color. azure); // letter white // G. fillrectangle (new system. drawing. solidbrush (color. blue), 0, 0, image. width, image. height); G. clear (color. brown); // background gray G. drawstring (checkcode, F, B, 3, 3); pen blackpen = new pen (color. black, 0); random Rand = new random (); system. io. memorystream MS = new system. io. memorystream (); image. save (MS, system. drawing. imaging. imageformat. JPEG); response. clearcontent (); response. contenttype = "image/JPEG"; response. binarywrite (Ms. toarray (); G. dispose (); image. dispose ();}}}
Add images to the login page
<Asp: Image id = "image1" runat = "server" imageurl = "PNG. aspx" onclick = "Refresh (this, 'png. aspx ');"/>
JS script
Function refresh ()
{
VaR url = "PNG. aspx? Id = ";
VaR r = math. Random () * 1000;
Url = URL + R;
Document. All ("image1"). src = URL;
Document. All ("loi_txtvc"). value = "";
Document. All ("loi_txtvc"). Focus ();
Return false;
} </SCRIPT>
The verification code textbox3 is the verification code input box.
If (base. session ["checkcode"] = NULL) {page. clientscript. registerstartupscript (page. clientscript. getType (), "myscripts", "<SCRIPT> alert (\" Verification Code expired! \ "); </SCRIPT>"); return;} If (textbox3.text! = Session ["checkcode"]. tostring () {page. clientscript. registerstartupscript (page. clientscript. getType (), "myscripts", "<SCRIPT> alert (\" Incorrect verification code! \ "); </SCRIPT>"); return ;}
C # refresh the verification code on the logon page