黑马程序员技术交流社区

标题: 怎样改把这个验证码用上? [打印本页]

作者: 李礼彬    时间: 2013-5-17 22:52
标题: 怎样改把这个验证码用上?
  1. 类定义:
  2. #region 验证码
  3.     public string sjnum(int n)
  4.     {
  5.         string strchar = "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,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";
  6.         string[] VcArray = strchar.Split(',');
  7.         string VNum = "";
  8.         int temp = -1;
  9.         Random rand = new Random();
  10.         for (int i = 1; i < n + 1; i++)
  11.         {
  12.             if (temp != -1)
  13.             {
  14.                 rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
  15.             }
  16.             int t = rand.Next(61);
  17.             if (temp != -1 && temp == t)
  18.             {
  19.                 return sjnum(n);
  20.             }
  21.             temp = t;
  22.             VNum += VcArray[t];
  23.         }
  24.         return VNum;
  25.     }//登录验证
  26. #endregion
  27. 登录界面代码:
  28. protected void Page_Load(object sender, EventArgs e)
  29.     {
  30.         if (!Page.IsPostBack)
  31.         {
  32.            
  33.         }
  34.     }
  35.     protected void Button2_Click(object sender, EventArgs e)
  36.     {
  37.         Response.Redirect("index.aspx");
  38.     }
  39.     protected void Button1_Click(object sender, EventArgs e)
  40.     {
  41.         gly ds1 = new gly();
  42.         if (TextBox1.Text == "" || TextBox2.Text == "")
  43.         {
  44.           gly.infoAndRedirect("登录名和密码不能为空!", "login.aspx");
  45.         }
  46.         else
  47.         {
  48.             if (TextBox3.Text == Label1.Text)
  49.             {
  50.                 ds1.gzh = TextBox1.Text;
  51.                 ds1.gmm = TextBox2.Text;
  52.                 int flag = ds1.glylog();
  53.                 if (flag == 1)
  54.                 {
  55.                   gly.infoAndRedirect("登录成功!", "../admin/newsdatas.aspx");
  56.                 }
  57.                 else
  58.                 {
  59.                   gly.infoAndRedirect("信息有误!", "login.aspx");
  60.                 }
  61.             }
  62.         }
  63.     }

复制代码
登录的代码里改,谢谢!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2