Chinaunix首页 | 论坛 | 博客
  • 博客访问: 897920
  • 博文数量: 215
  • 博客积分: 10062
  • 博客等级: 上将
  • 技术积分: 2235
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-01 13:21
文章分类

全部博文(215)

文章存档

2012年(1)

2011年(24)

2009年(16)

2008年(91)

2007年(83)

我的朋友

分类:

2007-12-12 16:56:51

//逻辑的页面:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class users_Validate : System.Web.UI.Page
{
    private 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','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'
        };
    protected void Page_Load(object sender, EventArgs e)
    {
        string VNum = GenerateRandom(5);
        Session["VNum"] = VNum;
        Validate_code(VNum);
    }
    //获得随即的5个字符
    private string GenerateRandom(int length)
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder(62);
        System.Random r = new Random();
        for (int i = 0; i < length; i++)
        {
            sb.Append(constant[r.Next(62)]);
        }
        return sb.ToString();
    }
    //将5个字符画在图片中
    private void Validate_code(string sValue)
    {

        int gHeigth = Int32.Parse((sValue.Length * 11).ToString());
        System.Drawing.Bitmap Img = new System.Drawing.Bitmap(gHeigth, 20);
        System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(Img);
        g.DrawString(sValue, new System.Drawing.Font("Arial", 10), new System.Drawing.SolidBrush(System.Drawing.Color.Blue), 3, 3);
        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        Img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
        Response.ClearContent();
        Response.ContentType = "image/gif";
        Response.BinaryWrite(ms.ToArray());
        g.Dispose();
        Img.Dispose();
        Response.End();
    }
}
 
//调用的页面:
  using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Model;
using DAL;
public partial class Default4 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.Image2.ImageUrl = "Validate.aspx";
        }
        if (Session["VNum"] != null)
        {
            ViewState["VNum"] = Session["VNum"].ToString();
        }
    }
    protected void btnok_Click(object sender, EventArgs e)
    {
        if (this.txtma.Text == ViewState["VNum"].ToString())
        {
            Model.Enterinfo enterinfo = new Enterinfo();
            enterinfo.Username = this.txtusername1.Text.Trim();
            enterinfo.Truename = this.txtusername2.Text.Trim();
            enterinfo.Password = this.txtpwd1.Text.Trim();
            enterinfo.Email = this.txtemail.Text.Trim();
            enterinfo.Password = this.txtpwd1.Text.Trim();
            enterinfo.Pwdquest = this.txtquestion.Text.Trim();
            enterinfo.Pwdanswer = this.txtanswer.Text.Trim();
            DAL.User user = new User();
            if (user.ISIenterinfo(enterinfo) > 0)
            {
                Response.Redirect("success.aspx");
            }   
        }    
    }
}

阅读(466) | 评论(0) | 转发(0) |
0

上一篇:配置数据源

下一篇:JSF标签库的使用

给主人留下些什么吧!~~