解决方案 »

  1.   

    做过相似的,网上有相似的,你参考一下,
    http://www.cnblogs.com/yoyiorlee/archive/2009/09/20/1570631.html
      

  2.   

    验证码登陆系统
    //登陆页面设置
    <asp:TextBox ID="txtUid" runat="server" Font-Size="9pt" Width="120px" 
              BackColor="White"></asp:TextBox>//用户登陆名
    <asp:TextBox ID="txtPwd" runat="server" Font-Size="9pt" TextMode="Password"
              Width="120px" style="margin-left: 0px" BackColor="White">
           </asp:TextBox>//用户登陆密码
    <asp:TextBox ID="txtVali" runat="server" Font-Size="9pt" Width="60px" 
              BackColor="White"></asp:TextBox>//登陆验证码
    <img id="Img1" align="left" alt="看不清,请点击我!" onclick="this.src=this.src+'?'" 
              src="../youyu/CheckCode.aspx" style="width: 49px; height: 22px" />//验证码存放地址
    <asp:ImageButton ID="ImageManage" runat="server" ImageUrl="~/image/b1.jpg" 
                      OnClick="btnLoad_Click"/>//登陆按钮
    //用户登陆验证
      protected void btnLoad_Click(object sender, ImageClickEventArgs e)
        {
            HttpCookie cookie = Request.Cookies["CheckCode"];//记录验证CK
            if (String.Compare(cookie.Value, txtVali.Text, true) != 0)
            {            Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
            }//CodeGo.net/        else
            {
               DataSet ds = DB.reDs("select * from tb_HuenLian where UserName='" + txtUid.Text.Trim() + "' and PassWord='" + txtPwd.Text.Trim() + "'");
                int i = this.checkLogin(txtUid.Text, txtPwd.Text);
                if (i > 0)
                {
                    Session["id"] = ds.Tables[0].Rows[0][0].ToString();//记录索引项
                    Session["UserName"] = this.txtUid.Text;//记住用户名
                    Session["PassWord"] = this.txtPwd.Text;//记住密码
                    Page.Response.Redirect("Yonghu.aspx");//如果正确跳转到指定目录
                }
                else
                {
                    Response.Write("<script lanuage=javascript>alert('用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
                }
            }
    }
    //使用checkLogin方法验证数据库信息是否正确
    public int checkLogin(string loginName, string loginPwd)
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conn"]);
            SqlCommand myCommand = new SqlCommand("select count(*) from tb_HuenLian where UserName=@loginName and PassWord=@loginPwd", con);
            myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.NVarChar, 20));
            myCommand.Parameters["@loginName"].Value = loginName;
            myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.NVarChar, 50));
            myCommand.Parameters["@loginPwd"].Value = loginPwd;
            myCommand.Connection.Open();
            int i = (int)myCommand.ExecuteScalar();
            myCommand.Connection.Close();
            return i;
        }