首页 asp.net 生成验证码

asp.net 生成验证码

举报
开通vip

asp.net 生成验证码asp.net 生成验证码 ??Ò??öÎÒÓõÄ??ÔÚÒ?µ??ÉÍ?Æ?µ?ÓÃ?ÍOKÁË?? csÎÄ?þÄÚÈÝÈçÏÂ?º ------------------------------------------------------ using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Secu...

asp.net 生成验证码
asp.net 生成验证码 ??Ò??öÎÒÓõÄ??ÔÚÒ?µ??ÉÍ?Æ?µ?ÓÃ?ÍOKÁË?? csÎÄ?þÄÚÈÝÈçÏÂ?º ------------------------------------------------------ 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.Drawing; public partial class validate : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if(!this.IsPostBack) { this.GenImg(this.GetCode(4)); } } //?úÉúËæ?ú×Ö?û?? private string GetCode(int num) { string[] source={"1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I", "J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"}; string code=""; Random rd=new Random(); for(int i=0;i < num;i++) { code += source[rd.Next(0,source.Length)]; } return code; } //Éú?ÉÍ?Æ? private void GenImg(string code) { Random rd = new Random(); Bitmap myPalette = new Bitmap(120, 60); //??ÒåÒ??ö?,?å Graphics gh = Graphics.FromImage(myPalette); //ÔÚ?,?åÉÏ??Òå?æÍ?µÄʵÀý Rectangle rc = new Rectangle(0, 0, 120, 60); //??ÒåÒ??ö?ØÐÎ String picPath = Server.MapPath("pic/bg" + rd.Next(1,4).ToString().Trim() + ".jpg" ); Bitmap imagefile = (Bitmap)System.Drawing.Image.FromFile(picPath, true); //µÃµ?Ò?ÕÅÎ?Í? TextureBrush texture = new TextureBrush(imagefile); //ÒÔÍ?Æ???Á??æÍ?Ë? Color[] fontcolor = { Color.Black, Color.Red, Color.DarkBlue, Color.Green, Color.Red, Color.Brown, Color.DarkCyan, Color.Purple }; //??Òå 8 ÖÖÑÕÉ? String[] fontname = { "Verdana", "System", "Comic Sans MS", "Arial", "ËÎÌå" }; //??Òå 5 ÖÖ×ÖÌå Font myfont; //×ÖÌå??Òå SolidBrush mybrush; //?,?Ê??Òå gh.FillRectangle(texture, rc);//Ê?ÓÃ?æÍ?Ë?Ìî?ä?ØÐÎ??µ??˵õ?Í?Æ????? for (short i = 0; i <= code.Length - 1; i++) { myfont = new Font(fontname[rd.Next(0, 5)],30,FontStyle.Italic); //Ëæ?ú×ÖÌå,42ºÅ??Ð?Ìå mybrush = new SolidBrush(fontcolor[rd.Next(0, 8)]); //Ëæ?úÑÕÉ? gh.DrawString(code.Substring(i,1) , myfont, mybrush, 3 + (i * 23),rd.Next(1,8));//ÔÚ?ØÐÎÄÚ?,?ö×Ö?û?? } myPalette.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//??Í?Æ?ÏÔÊ??öÀ? Session["ValidateCode"] = code;//??×Ö?û?????æµ?SessionÖÐ??ÒÔ?ãÐèÒªÊ??øÐÐÑéÖ? gh.Dispose(); myPalette.Dispose(); } }
本文档为【asp&#46;net 生成验证码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_083599
暂无简介~
格式:doc
大小:16KB
软件:Word
页数:0
分类:
上传时间:2018-03-18
浏览量:5