登陆时判断数据库是否存在该用户和记住我的实现

来源:互联网 发布:图书管理系统数据库表 编辑:程序博客网 时间:2024/05/17 01:53

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace Sina
{
    public partial class denglu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {  
            if (!IsPostBack)
            {
              
                if (Request.Cookies["Username"] != null)
                { 
                    this.TextBox1.Text = Request.Cookies["Username"].Value;
                }
                if (Request.Cookies["Username"] != null && Request.Cookies["pass"] != null)
                {
                    this.TextBox1.Text = Request.Cookies["Username"].Value;
                    string xx=Request.Cookies["pass"].Value;
                    TextBox2.Text = xx;
                }
            }
        }

        private void Date()
        {
          if (CheckBox1.Checked)
            {
                Response.Cookies["Username"].Expires = DateTime.Now.AddDays(7);
                Response.Cookies["pass"].Expires = DateTime.Now.AddDays(7);
            }
            Response.Cookies["Username"].Value = this.TextBox1.Text.Trim();
            Response.Cookies["pass"].Value = this.TextBox2.Text.Trim();
        }

  

        private void LoadDate()
        {
            string UUsername = TextBox1.Text;
           Sina.BLL.yonghu count = new Sina.BLL.yonghu();
            int a = count.GetRecordCount("Username=" + "'" + UUsername + "'");
            if (a > 0)
            {
                Sina.BLL.yonghu show = new Sina.BLL.yonghu();
                DataSet ds = show.GetList("Username=" + "'" + UUsername + "'");
                string Username = ds.Tables[0].Rows[0]["Username"].ToString();
                string Pass = ds.Tables[0].Rows[0]["Pass"].ToString();
              
                if (Username == TextBox1.Text && Pass == TextBox2.Text)
                {
                    string guid = ds.Tables[0].Rows[0]["Guidclass"].ToString();
                    Session["guid"] = guid;
                    Session["username"] = Username;
                 
            Response.Redirect("xindex.aspx?Username=" + UUsername);
                }
                else if (Username == TextBox1.Text && Pass != TextBox2.Text)
                {
                    this.lbl.Text = "密码不正确,请重新输入!";
                }
            }
            else
            {
                this.lbl.Text = "该用户不存在,请您到注册页注册!";
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Date();
            LoadDate();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("zhuce.aspx");
        }
    }
}