验证码中的等于号怎么输入 C#中生成验证码的类
C#中生成验证码的类
在很多网站中都会用到验证码的功能来防止非法注册用户 下面我就提供一个生成验证码的类
代码如下 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 checkcode System Web UI Page { protected void Page_Load(object sender EventArgs e)
{ CreateCheckCodeImage(GenerateCheckCode()) }
private string GenerateCheckCode()
{ int number char code string checkCode = String Empty System Random random = new Random()
for (int i = i < i++)
{ number = random Next()
if (number % == )
code = (char)( + (char)(number % )) else code = (char)( A + (char)(number % ))
checkCode += code ToString() } Response Cookies Add(new HttpCookie( CheckCode checkCode)) return checkCode }
private void CreateCheckCodeImage(string checkCode)
{ if (checkCode == null || checkCode Trim() == String Empty)
return System Drawing Bitmap image = new System Drawing Bitmap((int)Math Ceiling((checkCode Length * )) ) Graphics g = Graphics FromImage(image) try { //生成随机生成器Random random = new Random() //清空图片背景色g Clear(Color White) //画图片的背景噪音线for (int i = i < i++)
{ int x = random Next(image Width) int x = random Next(image Width) int y = random Next(image Height) int y = random Next(image Height) g DrawLine(new Pen(Color Black) x y x y ) } Font font = new System Drawing Font( Arial (System Drawing FontStyle Bold | System Drawing FontStyle Italic)) System Drawing Drawing D LinearGradientBrush brush = new System Drawing Drawing D LinearGradientBrush(new Rectangle( image Width image Height) Color Blue Color DarkRed f true) g DrawString(checkCode font brush ) //画图片的前景噪音点for (int i = i < i++)
{ int x = random Next(image Width) int y = random Next(image Height) image SetPixel(x y Color FromArgb(random Next())) } //画图片的边框线g DrawRectangle(new Pen(Color Silver) image Width image Height ) System IO MemoryStream ms = new System IO MemoryStream() image Save(ms System Drawing Imaging ImageFormat Gif) Response ClearContent() Response ContentType = image/Gif Response BinaryWrite(ms ToArray()) } finally { g Dispose() image Dispose() }

lishixinzhi/Article/program/net/201311/13063
- 上一篇
淘宝怎么换绑支付宝 以前的手机停机了,淘宝购物的支付宝付款有时需要验证码,有时又不用,怎么回事?怎么解决?
以前的手机停机了,淘宝购物的支付宝付款有时需要验证码,有时又不用,怎么回事?怎么解决? 以前的手机停机了,淘宝购物的支付宝付款有时需要验证码,有时又不用,怎么回事?怎么解决?有时需要验证码是淘宝支付系
- 下一篇
这个妹妹我曾见过的原文在多少章 慕容承携素馔见过原文|翻译|赏析_原文作者简介!
慕容承携素馔见过原文 翻译 赏析_原文作者简介 慕容承携素馔见过 [作者] 王维 [朝代] 唐代 纱帽乌皮几,闲居懒赋诗。门看五柳识,年算六身知。灵寿君王赐,雕胡弟子炊。空劳酒食馔,持底解人颐。《慕容
爱学记

微信收款码
支付宝收款码