示范地址
http://www.qol8.com/ValifyCode.aspx觉得有兴趣的可以找我,只有周末上
[email protected]下载地址
http://h.thec.cn/Kissogram/Downloads/ValifyCode.rar

解决方案 »

  1.   

    很不错.我有Reflector,可以看代码,谢谢
      

  2.   

    哈哈,有意思得东西,我也有Reflector
      

  3.   

    namespace Kissogram.Common.Security
    {
        using System;
        using System.IO;
        using System.Web;
        using System.Drawing;    //GIF验证码类
        public class Validate
        {
            //设置最少4位验证码
            private byte TrueValidateCodeCount = 4;
            public byte ValidateCodeCount
            {
                get
                {
                    return TrueValidateCodeCount;
                }
                set
                {
                    //验证码至少为3位
                    if (value > 4)
                        TrueValidateCodeCount = value;
                }
            }
            protected string ValidateCode = "";
            //是否消除锯齿
            public bool FontTextRenderingHint = false;
            //验证码字体
            public string ValidateCodeFont = "Arial";
            //验证码型号(像素)
            public float ValidateCodeSize = 13;
            public int ImageHeight = 23;
            //定义验证码中所有的字符
            public string AllChar = "1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,W,X,Y,Z";        //获得随机四位数
            private void CreateValidate()
            {
                ValidateCode = "";
                //将验证码中所有的字符保存在一个字符串数组中
                string[] CharArray = AllChar.Split(',');
                int Temp = -1;
                //生成一个随机对象
                Random RandCode = new Random();
                //根据验证码的位数循环
                for (int i = 0; i < ValidateCodeCount; i++)
                {
                    //主要是防止生成相同的验证码
                    if (Temp != -1)
                    {
                        //加入时间的刻度
                        RandCode = new Random(i * Temp * ((int)DateTime.Now.Ticks));
                    }
                    int t = RandCode.Next(35);
                    if (Temp == t)
                    {
                        //相等的话重新生成
                        CreateValidate();
                    }
                    Temp = t;
                    ValidateCode += CharArray[Temp];
                }
                //错误检测,去除超过指定位数的验证码
                if (ValidateCode.Length > TrueValidateCodeCount)
                    ValidateCode = ValidateCode.Remove(TrueValidateCodeCount);
            }
            //生成一帧的BMP图象
            private void CreateImageBmp(out Bitmap ImageFrame)
            {
                //获得验证码字符
                char[] CodeCharArray = ValidateCode.ToCharArray(0, ValidateCodeCount);
                //图像的宽度-与验证码的长度成一定比例
                int ImageWidth = (int)(TrueValidateCodeCount * ValidateCodeSize * 1.3 + 4);
                //创建一个长20,宽iwidth的图像对象
                ImageFrame = new Bitmap(ImageWidth, ImageHeight);
                //创建一个新绘图对象
                Graphics ImageGraphics = Graphics.FromImage(ImageFrame);
                //清除背景色,并填充背景色
                //Note:Color.Transparent为透明
                ImageGraphics.Clear(Color.White);
                //绘图用的字体和字号
                Font CodeFont = new Font(ValidateCodeFont, ValidateCodeSize, FontStyle.Bold);
                //绘图用的刷子大小
                Brush ImageBrush = new SolidBrush(Color.Red);
                //字体高度计算
                int FontHeight = (int)Math.Max(ImageHeight - ValidateCodeSize - 3, 2);
                //创建随机对象
                Random rand = new Random();
                //开始随机安排字符的位置,并画到图像里
                for (int i = 0; i < TrueValidateCodeCount; i++)
                {
                    //生成随机点,决定字符串的开始输出范围
                    int[] FontCoordinate = new int[2];
                    FontCoordinate[0] = (int)(i * ValidateCodeSize + rand.Next(1)) + 3;
                    FontCoordinate[1] = rand.Next(FontHeight);
                    Point FontDrawPoint = new Point(FontCoordinate[0], FontCoordinate[1]);
                    //消除锯齿操作
                    if (FontTextRenderingHint)
                        ImageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
                    else
                        ImageGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                    //格式化刷子属性-用指定的刷子、颜色等在指定的范围内画图
                    ImageGraphics.DrawString(CodeCharArray[i].ToString(), CodeFont, ImageBrush, FontDrawPoint);
                }
                ImageGraphics.Dispose();
            }
            //处理生成的BMP
            private void DisposeImageBmp(ref Bitmap ImageFrame)
            {
                //创建绘图对象
                Graphics ImageGraphics = Graphics.FromImage(ImageFrame);
                //创建铅笔对象
                Pen ImagePen = new Pen(Color.Red, 1);
                //创建随机对象
                Random rand = new Random();
                //创建随机点
                Point[] RandPoint = new Point[2];
                //随机画线
                for (int i = 0; i < 15; i++)
                {
                    RandPoint[0] = new Point(rand.Next(ImageFrame.Width), rand.Next(ImageFrame.Height));
                    RandPoint[1] = new Point(rand.Next(ImageFrame.Width), rand.Next(ImageFrame.Height));
                    ImageGraphics.DrawLine(ImagePen, RandPoint[0], RandPoint[1]);
                }
                ImageGraphics.Dispose();
            }
            //创建GIF动画
            private void CreateImageGif()
            {
                Bitmap ImageFrame;
                Kissogram.Drawing.Gif.AnimatedGifEncoder GifPic = new Kissogram.Drawing.Gif.AnimatedGifEncoder();
                MemoryStream BmpMemory = new MemoryStream();
                GifPic.Start();
                //确保视觉残留
                GifPic.SetDelay(5);
                //-1:no repeat,0:always repeat
                GifPic.SetRepeat(0);
                for (int i = 0; i < 20; i++)
                {
                    //创建一帧的图像
                    CreateImageBmp(out ImageFrame);
                    //生成随机线条
                    DisposeImageBmp(ref ImageFrame);
                    //输出绘图,将图像保存到指定的流
                    ImageFrame.Save(BmpMemory, System.Drawing.Imaging.ImageFormat.Png);
                    GifPic.AddFrame(Image.FromStream(BmpMemory));
                    BmpMemory = new MemoryStream();
                }
                GifPic.OutPut(ref BmpMemory);
                HttpContext.Current.Response.ClearContent();
                //配置输出类型
                HttpContext.Current.Response.ContentType = "image/Gif";
                //输出内容
                HttpContext.Current.Response.BinaryWrite(BmpMemory.ToArray());
                BmpMemory.Close();
                BmpMemory.Dispose();
            }
            //输出验证码
            public void OutPutValidate(string ValidateCodeSession)
            {
                CreateValidate();
                CreateImageGif();
                //把生成的验证码输入到SESSION
                HttpContext.Current.Session[ValidateCodeSession] = ValidateCode;
            }
        }
    }这是源代码,免得大家去反编译了,不过得希望有良心的不要抄了以后说自己写的
      

  4.   

    主要针对注册机暴力营销
    每一帧都划了很多线,确保一般的注册机在分解了GIF后也不容易读出来
    人有视觉残留,所以读起来不是很困难大家有对单帧处理能让注册机更难读取的办法请联系我
      

  5.   

    GIF动画生成类使用了
    http://www.codeproject.com/dotnet/NGif.asp
    上的一个
    再进行了下小修改
      

  6.   

    jiewenxu(),谢谢你。
    我试验了一下,为什么无论我在网页上添加什么内容都不能显示出来,只能显示出那个跳动的动画?为什么呀?
      

  7.   

    注意
    这个不是一个网页
    这是输出为GIF图片的(image/gif)使用的时候和其他的验证码程序一样,在网页中调用
    <image src="validycode.aspx"/>
      

  8.   

    http://www.codeproject.com/dotnet/NGif/NGif_src.zip
    开源组件
      

  9.   

    为什么用不了``
    Kissogram.Drawing.Gif.AnimatedGifEncoder GifPic = new Kissogram.Drawing.Gif.AnimatedGifEncoder();出错了
      

  10.   

    错误提示。。?
    我包里提供的ValidyCode.aspx不是就能用么
      

  11.   

    为什么用不了``
    Kissogram.Drawing.Gif.AnimatedGifEncoder GifPic = new Kissogram.Drawing.Gif.AnimatedGifEncoder();出错了
    ------------------------
    还是下载我提供的包
    DLL里面还有一个命名空间是 Kissogram.Drawing.Gif
    你直接拷贝我上面发的代码会缺少这个GIF生成类
      

  12.   

    我下了个Reflector``就是不会用
      

  13.   

    为什么用不了``
    Kissogram.Drawing.Gif.AnimatedGifEncoder GifPic = new Kissogram.Drawing.Gif.AnimatedGifEncoder();出错了
    ------------------------
    还是下载我提供的包
    DLL里面还有一个命名空间是 Kissogram.Drawing.Gif
    你直接拷贝我上面发的代码会缺少这个GIF生成类
    -----------------------------------------------------------------
    我拷了``可怎么把这个DLL加到项目里去啊
      

  14.   

    直接用你打包的那个还是出错```未实例化
    怎么可能
    DLL有没有放错阿
      

  15.   

    确实不错 不过你创建随机码其实可以更简单:
    string AllChar = "1234567890ABCDEFGHIJKLMNOPQRSTUWXYZ";Random r = new Random();
    string result = "";
    for (int i=0; i<4; i++)
    {
    result += AllChar[r.Next(AllChar.Length)];
    }
    result既是随机了
      

  16.   

    直接用你打包的那个还是出错```未实例化
    怎么可能
    DLL有没有放错阿可就是说未实例化,我是把你的那个直接放到wwwroot下面````然后运行``有什么要注意的吗?
      

  17.   

    补一个下载地址
    http://qol8.com/Down/ValifyCode.rar
      

  18.   

    晕,被linkgate拒绝了
    点这个下载
    http://qol8.com/Down/ValifyCode.htm
      

  19.   

    麻烦楼主将Kissogram.Drawing.Gif.AnimatedGifEncoder这个类的详细代码贴出来,我用VB,想研究研究你的代码,可只能察看你的类定义,至于详细的代码只用C#察看,转来转去太麻烦了,所以麻烦楼主一下,小弟先谢谢了!!!!!!!!!!!!!!!!!!
      

  20.   

    http://www.cnblogs.com/jillzhang/archive/2008/05/12/1128263.html
      

  21.   

    http://sandbox.palmnet.me.uk/gifcaptcha/在网上找到的一个比较cool的算法,这才是我当初真正的想法,利用视觉残留来做验证码另,由于有很多人通过电邮跟我要源码,所以我在google开了个项目
    http://code.google.com/p/awesomecaptcha/
    有兴趣的同学可以去download
      

  22.   

    请问 Kissogram.Drawing.Gif.AnimatedGifEncoder这里面怎么修改的啊   急求指教
      

  23.   

    所有源代码下载地址:
    http://awesomecaptcha.googlecode.com/files/attachments_2011_04_28.zip
      

  24.   

    皕应的HCaptcha还不错,动画验证码方面做得会比较好,我们现在做验证码的时候已经没必要自己开发了,直接用这个免费服务就搞定了 http://www.hinsitecom 安全性等方面由这些服务来提供就够了。