验证码
来源:互联网 发布:淘宝lol半价点券来源 编辑:程序博客网 时间:2024/05/22 11:42
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Ticket.Web
{
public partial class VerifyCode : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpContext.Current.Response.Cache.SetNoStore();
HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
string checkCode = AppCode.Sys.CreateRandomCode(4);
AppCode.Sys.CreateImage(checkCode);
//Session[Globals.VerifyKeyName] = Sys.Encrypt(checkCode, ConfigurationManager.AppSettings["EncryptKey"]);
//Session["VerifyCode"] = Common.Cryptography.AesEncode(verifyCode, AppCode.BaseConfig.EncryptKey);
//HttpContext.Current.Response.Cache.SetNoStore();
//HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddSeconds(-1));
//HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
//System.Drawing.Color bg = System.Drawing.Color.FromArgb(240, 243, 248);
//string verifyCode = Ticket.Plugin.Services.VerifyImage.CreateVerifyCode(4, false);
//Plugin.Services.VerifyImageProvider.GetInstance("JpegImage").GenerateImage(verifyCode, 80, 30, bg, 23);
Session["VerifyCode"] = Common.Cryptography.AesEncode(checkCode, AppCode.BaseConfig.EncryptKey);
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using System.IO;
using System.Text;
using System.Drawing.Imaging;
namespace Ticket.Web.AppCode
{
public class Sys
{
/// <summary>
/// 生成验证码图片
/// </summary>
/// <param name="checkCode"></param>
public static void CreateImage(string checkCode)
{
int width = (int)(checkCode.Length * 17.5);
Bitmap image = new Bitmap(width, 25);
Graphics graphics = Graphics.FromImage(image);
Font font = new Font("Arial", 14, FontStyle.Bold);
Brush brush = new SolidBrush(Color.FromArgb(0, 0, 0));
graphics.Clear(Color.FromArgb(0xdb, 0xdb, 0xdb));
graphics.DrawString(checkCode, font, brush, (float)3f, (float)3f);
//线条颜色
Pen pen = new Pen(Color.SlateGray, 0f);
Random random = new Random();
for (int i = 0; i < 2; i++)
{
int num3 = random.Next(image.Height);
graphics.DrawEllipse(pen, 2, num3, image.Width, num3);
}
MemoryStream stream = new MemoryStream();
image.Save(stream, ImageFormat.Jpeg);
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.ContentType = "image/jpeg";
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
stream.Close();
graphics.Dispose();
image.Dispose();
}
/// <summary>
/// 生成随机码
/// </summary>
/// <param name="codeCount">代码位数</param>
/// <returns>字符串</returns>
public static string CreateRandomCode(int codeCount)
{
//,a,b,c,d,e,f,g,h,i,j,k,k,m,n,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,J,K,L,M,N,P,P,Q,R,S,T,U,W,X,Y,Z
string[] strArray = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,k,m,n,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,J,J,K,L,M,N,P,P,Q,R,S,T,U,W,X,Y,Z".Split(new char[] { ',' });
string str2 = "";
int num = -1;
Random random = new Random();
for (int i = 0; i < codeCount; i++)
{
if (num != -1)
{
random = new Random((i * num) * ((int)DateTime.Now.Ticks));
}
int index = random.Next(61);
if (num == index)
{
return CreateRandomCode(codeCount);
}
num = index;
str2 = str2 + strArray[index];
}
return str2;
}
}
}
- 简单验证码验证
- 验证验证码
- 验证码的验证
- 验证码的验证
- 验证码客户端验证
- java验证码 验证
- 验证码验证模块
- 手机短信验证码验证
- 验证验证码
- 表单验证+验证码
- thinkphp 验证码功能(验证验证码)
- 验证码
- 验证码
- 验证码
- 验证码
- 验证码
- 验证码
- 验证码
- 学习
- 第一个WEB Server程序
- 分块上传大文件
- 恶意代码之网页无限
- 移动视频传输系统
- 验证码
- jsessionid解释
- RTSP server比較
- 启动和关闭MySQL服务
- flex 嵌入 iframe 点iframe 外面的区域 iframe会消失。。 解决办法
- asp、net使用json
- 几个研究RTSP的参考网站
- 虚拟机同IP多域名问题
- D3D键盘输入处理