This article mainly introduces a simple ASP.NET verification code in detail, which has certain reference value. Interested friends can refer to it
The example in this article shares ASP with everyone. The specific code of NET verification code is for your reference. The specific content is as follows
I mainly see interference lines. If there are no interference lines in a verification code, at least it must be in the layout of noise and random codes. Work hard:
/// <summary> /// 验证码生成类 /// </summary> public class verify_code : IHttpHandler, IRequiresSessionState { public void ProcessRequest(HttpContext context) { int codeW = 80; int codeH = 22; int fontSize = 16; string chkCode = string.Empty; //颜色列表,用于验证码、噪线、噪点 Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue }; //字体列表,用于验证码 string[] font = { "Times New Roman", "Verdana", "Arial", "Gungsuh", "Impact" }; //验证码的字符集,去掉了一些容易混淆的字符 char[] character = { '0', '1', '2', '3', '4', '5', '6', '8', '9' }; Random rnd = new Random(); //生成验证码字符串 for (int i = 0; i < 4; i++) { chkCode += character[rnd.Next(character.Length)]; } //写入Session context.Session["sys_verify_code"] = chkCode; //创建画布 Bitmap bmp = new Bitmap(codeW, codeH); Graphics g = Graphics.FromImage(bmp); g.Clear(Color.White); //画噪线 for (int i = 0; i < 4; i++) { int x1 = rnd.Next(codeW); int y1 = rnd.Next(codeH); int x2 = rnd.Next(codeW); int y2 = rnd.Next(codeH); Color clr = color[rnd.Next(color.Length)]; g.DrawLine(new Pen(clr), x1, y1, x2, y2); } //画验证码字符串 for (int i = 0; i < chkCode.Length; i++) { string fnt = font[rnd.Next(font.Length)]; Font ft = new Font(fnt, fontSize); Color clr = color[rnd.Next(color.Length)]; g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 18 + 2, (float)0); } //画噪点 for (int i = 0; i < 100; i++) { int x = rnd.Next(bmp.Width); int y = rnd.Next(bmp.Height); Color clr = color[rnd.Next(color.Length)]; bmp.SetPixel(x, y, clr); } //清除该页输出缓存,设置该页无缓存 context.Response.Buffer = true; context.Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0); context.Response.Expires = 0; context.Response.CacheControl = "no-cache"; context.Response.AppendHeader("Pragma", "No-Cache"); //将验证码图片写入内存流,并将其以 "image/Png" 格式输出 MemoryStream ms = new MemoryStream(); try { bmp.Save(ms, ImageFormat.Png); context.Response.ClearContent(); context.Response.ContentType = "image/Png"; context.Response.BinaryWrite(ms.ToArray()); } finally { //显式释放资源 bmp.Dispose(); g.Dispose(); } } public bool IsReusable { get { return false; } } }
Basic verification generation code demo:
using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Web; public partial class image : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string tmp = RndNum(4); HttpCookie a = new HttpCookie("ImageV", tmp); Response.Cookies.Add(a); this.ValidateCode(tmp); } private void ValidateCode(string VNum) { Bitmap Img = null; Graphics g = null; MemoryStream ms = null; int gheight = VNum.Length * 12; Img = new Bitmap(gheight, 25); g = Graphics.FromImage(Img); //背景颜色 g.Clear(Color.White); //文字字体 Font f = new Font("Arial Black", 10); //文字颜色 SolidBrush s = new SolidBrush(Color.Black); g.DrawString(VNum, f, s, 3, 3); ms = new MemoryStream(); Img.Save(ms, ImageFormat.Jpeg); Response.ClearContent(); Response.ContentType = "image/Jpeg"; Response.BinaryWrite(ms.ToArray()); g.Dispose(); Img.Dispose(); Response.End(); } private 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,v,w,x,y,z"; string[] VcArray = Vchar.Split(new Char[] { ',' }); string VNum = ""; int temp = -1; Random rand = new Random(); for (int i = 1; i < VcodeNum + 1; i++) { if (temp != -1) { rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks)); } int t = rand.Next(35); if (temp != -1 && temp == t) { return RndNum(VcodeNum); } temp = t; VNum += VcArray[t]; } return VNum; } }
The above is the detailed content of ASP.NET verification code production. For more information, please follow other related articles on the PHP Chinese website!

1、启动PPT,新建一个空白文档,选择所有的文本框将其删除。2、执行插入-形状命令,在文档中拖拽出一个长方形,形状颜色填充为黑色。3、拖拽长方形将其拉长,执行插入-形状命令,拖拽出小正方形,设置填充颜色为白色。4、依次复制粘帖小正方形,使上下均匀分布在胶卷两侧,ctrl+a选择所有的之后,右键单击选择组合。5、执行插入-图片命令,在弹出的对话框中找到需插入的图片,点击打开,调整图片大小和位置。6、重复步骤5依次将其余的图片进行插入并设置,形成一个胶卷图片的形式。7、选择胶卷,执行动画-添加动画命

番茄小说封面怎么制作?番茄小说中是可以制作专属的小说封面,但是多数的小伙伴不知道番茄小说当中的封面该如何的制作,接下来就是小编为玩家带来的番茄小说封面制作方法图文教程,感兴趣的玩家快来一起看看吧!番茄小说使用教程番茄小说封面怎么制作1、首先打开番茄小说APP,进入到作品管理页面创建新书,选择下图箭头所示的【封面模板】;2、然后进入到封面模板页面,选择喜爱的封面模板;3、最后选择封面完成之后点击右上角【确认】即可。

手机Excel表格制作教程随着移动设备的普及和技术的不断进步,手机成为了我们日常生活和工作中不可或缺的工具之一。在手机上使用Excel表格,可以方便地进行数据记录、计算和分析,提高工作效率。本文将为大家分享手机Excel表格制作的基本操作和技巧。一、选择合适的应用程序目前市面上有很多可供选择的手机Excel应用程序,例如GoogleSheets、Micro

制作PPT的时候使用一些动画效果会比没有使用动画效果的显得活泼可爱,加上动画效果大家也许就喜欢看这个PPT,所以我们必须要学会PPT制作动画效果的方法。接下来,我将为大家详细介绍如何在PPT中添加动画效果。请继续往下阅读,认真学习这些步骤,相信对你会有所帮助!首先,打开我们自己制作的PPT,您会注意到这个PPT目前没有任何动画效果(如下图红色箭头所示)。2.然后,我们需要给图片添加动画效果,我们先选中图片,再单击菜单栏上边的【动画】按钮,(如下图红色圈出部分所示)。3.接下来,我们点击动画里边的

如何使用CSS制作倒计时效果的实现步骤倒计时效果是网页开发中常见的一个功能,可以为用户呈现倒计时的动态效果,给人以紧迫感和期待感。本文将介绍如何使用CSS来实现倒计时效果,并给出详细的实现步骤和代码示例。实现步骤如下:步骤一:HTML结构搭建首先,在HTML中创建一个div容器,用于包裹倒计时的内容。例如:<divclass="countd

一篇毕业论文一定要有封面、有目录、有结尾等等,这才能说明一篇论文是完整的。上期小编已经给小伙伴们分享了word怎么制作目录啦,这期给大家分享word封面的制作方法,不会制作的赶紧快来吧!1.首先,我们打开自己想要制作封面的word文档,如下图所示:2.然后,我们点击菜单栏上【章节】按钮,选择封面页,这个功能相当于一个封面库,你可以在里面自行挑选合适精美的封面,如下图红色圈出部分所示:3.点击后,你可以看到各种类型的封面,比如商务类型,适合公司合同、文档;简历类型,适合找工作投简历的朋友等等,还可

在软件中点击插入选项,新建空白演示文稿后输入主题和正文,设置文字和对象的放映顺序即可。教程适用型号:联想AIO520C系统:Windows10专业版版本:PowerPoint2022解析1打开PPT以后单击文件选项,选择新建空白演示文稿。2输入主题和正文,添加音频、图片、视频等效果。3最后按照要求设置文字和对象的放映顺序以及动画效果即可。补充:ppt中怎么插入视频1首先点击打开PowerPoint软件,进入后点击左上角插入选项。2接着点击右上角的视频选项。3弹出选框,点击来自文件的影片。4然后选

本篇文章主要给大家介绍PHP如何实现滑块验证图片,这里分享一个工具包“poster”,下面看看怎么实现吧,希望对需要的朋友有所帮助!


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools