上网浏览文章的时候,经常碰到非要你注册,才能够欣赏文章!
 而且上面都半都有验证码的。起初,以为就是把几幅图连在一块,在搞个图片随机调换,后来才知道,其实没这么简单。
   有没有哪位达人,高手告诉我,上怎么弄的啊
  我的MSN:[email protected]
 先谢谢各位了!!

解决方案 »

  1.   

    很简单的,搞1个随即数字+字母
    然后用GDI画出来,再搞点水印(比如几道横线),丢到界面上
    然后在别人注册的时候,用随即出来的字符串和他写的验证码比较就可以了(在代码里面)
      

  2.   

    protected void Page_Load(object sender, EventArgs e)
            {
                SetValidateCode();
                Response.Cache.SetNoStore();
            }
            private void SetValidateCode()
            {
                Bitmap newBitmap = new Bitmap(71, 23, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                Graphics g = Graphics.FromImage(newBitmap);
                Random r = new Random();
                g.Clear(Color.White);
                System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 71, 23), Color.Red, Color.Blue, 1.2f, true);            for (int i = 0; i < 50; i++)
                {
                    int x1 = r.Next(newBitmap.Width);
                    int x2 = r.Next(newBitmap.Width);
                    int y1 = r.Next(newBitmap.Height);
                    int y2 = r.Next(newBitmap.Height);
                    g.DrawLine(new Pen(Color.FromArgb(r.Next())), x1, y1, x2, y2);
                }
                for (int i = 0; i < 100; i++)
                {
                    int x = r.Next(newBitmap.Width);
                    int y = r.Next(newBitmap.Height);
                    newBitmap.SetPixel(x, y, Color.FromArgb(r.Next()));
                }
                string value = GenerateRandom(5);
                Session["Code"] = value;
                Font font = new Font("黑体", 14, System.Drawing.FontStyle.Bold);
                Random rr = new Random();
                int yy = rr.Next(1, 4);
                g.DrawString(value, font, brush, 2, yy);
                g.DrawRectangle(new Pen(Color.Silver), 0, 0, 70, 22);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                newBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
                Response.ClearContent();
                Response.ContentType = "image/gif";
                Response.BinaryWrite(ms.ToArray());
            }
            private static char[] constant =
            {
                '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'
            };
            public static string GenerateRandom(int Length)
            {
                System.Text.StringBuilder newRandom = new System.Text.StringBuilder(36);
                Random rd = new Random();
                for (int i = 0; i < Length; i++)
                {
                    newRandom.Append(constant[rd.Next(36)]);
                }
                return newRandom.ToString();
            }
        }
      

  3.   

    很简单的,上面的是validate.aspx
    然后在你需要的页面使用<img alt="验证码,看不清楚?请点击刷新验证码"
                        onclick="this.src='Validate.aspx'" src="Validate.aspx" style="cursor: pointer;
                        height: 26px" />
      

  4.   

    网上很多这样的例子,你搜索一下吧.给你一个:
    http://singlepine.cnblogs.com/articles/264894.html
      

  5.   

    http://mail-ricklee.cnblogs.com/archive/2006/05/29/411693.html
    里面有
    NickLee.Web.UI.VB.CaptchaControl-------------验证码控件(W3C)