zoukankan      html  css  js  c++  java
  • ASP.NET——基础 7、用注册码,防止暴力注册

    1、新建一个一般处理程序 ashx,在一般处理程序中使用Session,要为其实现的如下接口
    System.Web.SessionState.IRequiresSessionState
    2、一般处理程序的任务有两个,代码如下:
    • 生成一个验证码
    • 把验证码写入Session
    content.Response.ContentType="image/JPEG";
    using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(100,50))
    {
        using(System.Drawing.Graphics g=System.Drawing.Graphics(bitmap))
        {
            using(Font font=new System.Drawing.Font("宋体",12))
            {
                using(PointF point=new System.Drawing.PointF(0,10))
                {
                    Random rand=new Random();
                    int code=rand.Next(1000,9999);
                    string strCode=code.ToString();
                    HttpContext.Current.Session["Code"]=strCode;
                    g.DrawString(strCode,font,System.Drawing.Brush.Green,point);
                    bitmap.Save(content.Response.OutputStream,System.Drawing.Image.ImageFormat.Jpeg);
                }
            }
        }
    }
     
    3、CS中的代码如下:
    string Code=Convert.ToString(Session["Code"]);
    if(code==TextBox1.Text)
    {
        Response.Write("验证码输入正确!");
    }
    4、点击刷新
    <img src="YZM.ashx" onclick="this.src='YZM.ashx?aaa='+new Date()" />
  • 相关阅读:
    ping-tool
    yum 安装 5.6
    音视频编辑
    图表
    VC2013设置输出文件目录
    hdu 4679 Terrorist’s destroy 树形DP
    poj 3580 SuperMemo splay tree(重口味)
    hdu 1890 Robotic Sort splaytree+懒惰标记
    bzoj 1588 [HNOI2002]营业额统计 splay tree
    bzoj 1503 [NOI2004]郁闷的出纳员 splay tree
  • 原文地址:https://www.cnblogs.com/msdynax/p/2849415.html
Copyright © 2011-2022 走看看