特色栏目

ASP源码

PHP源码

.NET源码

JSP源码

游戏频道
专题合集
关闭菜单
首页> ASP.NET教程> asp.net 生成图片验证码

asp.net 生成图片验证码

时间:2009-06-30 16:30:32 作者:互联网

https://images.downcodes.comidentifyingcode.aspx里没有内容略。
id***ifyingcode.cs文件:
using System;
using Sy***m.Data;
using Sy***m.Configuration;
using Sy***m.Collections;
using Sy***m.Web;
using Sy***m.Web.Security;
using Sy***m.Web.UI;
using Sy***m.Web.UI.WebControls;
using Sy***m.Web.UI.WebControls.WebParts;
using Sy***m.Web.UI.HtmlControls;
using Sy***m.Drawing;
using Sy***m.Drawing.Imaging;
using Sy***m.IO;
public partial class identifyingcode : Sy***m.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string tmp = RndNum(4);
        HttpCookie a = new HttpCookie("ImageV", tmp);
        Re***nse.Cookies.Add(a);
        th***ValidateCode(tmp);

    }
    private void ValidateCode(string VNum)
    {
        Bitmap Img = null;
        Graphics g = null;
        MemoryStream ms = null;

        int gheight = VN***Length * 12;
        Img = new Bitmap(gheight, 25);
        g = Gr***ics.FromImage(Img);
        //背景颜色
        g.Clear(Co***.LightSteelBlue);
        //文字字体
        Font f = new Font("Arial Black", 10);
        //文字颜色
        SolidBrush s = new SolidBrush(Co***.RoyalBlue);
        g.***wString(VNum, f, s, 3, 3);
        ms = new MemoryStream();
        Img.Save(ms, Im***Format.Jpeg);
        Re***nse.ClearContent();
        Re***nse.ContentType = "images/Jpeg";
        Re***nse.BinaryWrite(ms***Array());
        g.***pose();
        Img.***pose();
        Re***nse.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 = Vc***.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)Da***ime.Now.Ticks));
            }

            int t = ra***Next(35);
            if (temp != -1 && temp == t)
            {
                return RndNum(VcodeNum);
            }
            temp = t;
            VNum += VcArray[t];
        }
        return VNum;
    }

}
 
使用方法:
在需要它的页面html里添加
 
 

  HttpCookieCollection cookies = Re***st.Cookies;
  string tmp = cookies["ImageV"].Value;
  然后比tmp与获取的较验证码文本框中的值是否相同
 
出处:http://enuosky.cnblogs.com/archive/2006/05/15/400954.html

相关文章 最新文章

相关应用

热门文章

猜你喜欢

返回顶部