oracle .net验证码
来源:互联网 发布:网络视听审核员怎么考 编辑:程序博客网 时间:2024/05/17 03:00
代码:
随机数代码:
private string CreateRandomCode(int codecount)
{
string allchar = "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,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[] allcharArray = allchar.Split(',');
string randomCode = "";
int temp;
Random rand = new Random();
for (int i = 0; i < codecount; i++)
{
int t = rand.Next(71);
temp = t;
randomCode +=allcharArray[t];
}
return randomCode;
}
干扰图片代码:
private void CreateImage(string checkcode)
{
int iwidth = (int)(checkcode.Length * 30);
System.Drawing.Bitmap image = new System.Drawing.Bitmap(iwidth,50);
Graphics g = Graphics.FromImage(image);
Font f = new System.Drawing.Font("Arial",25,System.Drawing.FontStyle.Bold);
Brush b = new System.Drawing.SolidBrush(Color.White);
g.Clear(Color.Red);
g.DrawString(checkcode,f,b,3,3);
Pen blackpen = new Pen(Color.Blue,0);
Random rand = new Random();
for (int i = 0; i < 4; i++)
{
int y = rand.Next(image.Height);
g.DrawLine(blackpen,0,y,image.Width,y);
}
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();
}
调用上面的两个方法的page_load
protected void Page_Load(object sender, EventArgs e)
{
string checkcode = CreateRandomCode(4);
Session["checkcode"] = checkcode;
CreateImage(checkcode);
}
- oracle .net验证码
- Asp.net验证码
- ASP.net 验证码
- ASP.NET验证码
- Asp.net验证码
- Asp.net验证码
- asp.net验证码
- asp.net 验证码
- ASP.NET 验证码
- .net(c#)验证码
- .net(c#)验证码
- asp.net验证码
- ASP.NET 验证码
- asp.net验证码
- asp.net验证码
- Asp.net验证码
- asp.net 验证码
- ASP.NET验证码
- 国内首套物联网专业丛书《物联网核心技术丛书》已经出版
- 一个链表创建、反转、打印的C语言代码
- Android - 批量发送短信的实现方式
- 指针专题 (C/C++) (C)
- 汇编语言超浓缩教程
- oracle .net验证码
- cocoa 设计模式
- background-attachment
- 过滤驱动笔记
- 二进制,八进制,十六进制,十进制间进行相互转换
- 算法讨论(七)--已排序数组中寻找两个数,其和等于给定的数
- 常见RGB颜色表
- tomcat环境中修改了server.xml配置文件后不起作用
- background-position