请问校验码这个功能要怎么实现呢
谢谢

解决方案 »

  1.   

    see an example hereASP.NET Controls to prevent automatic registrations from bots
    http://www.codeproject.com/aspnet/antiauto.asp
      

  2.   

    其实原理就是
    随机生成几个数字 写到LALBE OR 图片
    把该几个数字赋给个SESSION
    验证时候
    与TEXTBOX内容与SESSION比较而已
      

  3.   

    我自己写了一个
    http://henryfan.cnblogs.com/archive/2006/02/09/327565.html
      

  4.   

    我也写过,但是看到这帖高手太多,就不献丑了,给楼主提供一个实现的思路1,使用随机数(下面我用的是数字,当然你还可以加大写甚至小写or汉字)
    如:
    char[] Tempstr = new char[]{'0','1', '2','3','4','5','6','7','8','9'};
            string Rul = "";
            Random random = new Random();
            for (int i = 0; i < 3; i++)
            {
                Rul += Tempstr[random.Next(0, Tempstr.Length)].ToString();
            }
    这样就有了3位的随机数
    2,绘制生成图片(当然你也可以不绘制图片,而是把它传递到一个readonly的Textbox里,不过大家都是用图片验证码的,你也随大流吧!)
    这里主要使用到
    using System.IO;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Drawing.Drawing2D;
    具体实现你可以参考楼上高手的文档,我是菜鸟所以只说思路 ^_^
    3,把随机数赋给Session,这样成为每次用户输入后验证的依据。想了半天就这3点,也许是我只考虑到了这些吧~希望能给你点灵感~
      

  5.   

    private void Button1_Click(object sender, System.EventArgs e)
    {
    if(Request.Cookies["CheckCode"] == null)
    {
    Label1.Text = "您的浏览器设置已被禁用 Cookies,您必须设置浏览器允许使用 Cookies 选项后才能使用本系统。";
    Label1.Visible = true;
    return;
    } if(String.Compare(Request.Cookies["CheckCode"].Value, txtCheckCode.Text, true) != 0)
    {
    Label1.Text = "验证码错误,请输入正确的验证码。";
    Label1.Visible = true;
    return;
    }
    else
    {
    Label1.Text = "验证码正确。";
    Label1.Visible = true;
    return;
    }}