用户登录过程

protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.txt_user_name.Text.Trim() == "" || this.txt_user_pwd.Text.Trim() == "")
        {
            return;
        }
        else
        {
            Dqt.Reporter.BLL.user UserBLL = new Dqt.Reporter.BLL.user();
            Dqt.Reporter.Model.user UserModel = new Dqt.Reporter.Model.user();
            List<Dqt.Reporter.Model.user> userlist = UserBLL.GetModelList("(UserName='" + txt_user_name.Text.Trim() + "' or Email='" + txt_user_name.Text.Trim() + "')" + " and UserPassword='" + MFunction.Md5HashString(txt_user_pwd.Text.Trim().ToString()) + "'");
            if (userlist.Count > 0)
            {
                UserModel = userlist[0];
                UserModel.LastLoginIp = Request.UserHostAddress;
                UserModel.LastLoginTime = Util.TimeToUnixTimes(DateTime.Now.ToString());
                UserBLL.Update(UserModel);
                UserInstance.Instance.Dispose();
                string span = Util.TimeToUnixTimes(DateTime.Now.ToString()).ToString();
                string key = MFunction.Md5New(MFunction.Md5New(span + UserModel.UserId.ToString() + HttpUtility.UrlEncode(UserModel.UserName) + span));
                HttpCookie myCookie = new HttpCookie("dqtxjz");
                myCookie.Values.Add("LoginUserId", UserModel.UserId.ToString());
                myCookie.Values.Add("LoginUserName", HttpUtility.UrlEncode(UserModel.UserName));
                myCookie.Values.Add("TimeSpan", span);
                myCookie.Values.Add("Type", UserModel.Type.ToString());
                myCookie.Values.Add("Key", key);
                if (cb.Checked == true)
                {
                    myCookie.Expires = DateTime.Now.AddDays(15);
                }
                else
                {
                    myCookie.Expires = DateTime.Now.AddHours(12);
                }
                //    myCookie.Domain = "59miao.com";
                HttpContext.Current.Response.Cookies.Add(myCookie);
                urlrefer = Literal1.Text;
                if (string.IsNullOrEmpty(urlrefer) || urlrefer.Contains("login") || urlrefer.Contains("reg"))
                    Response.Redirect("/");
                else
                    Response.Redirect(urlrefer);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('用户名或者密码不正确!');", true);
                return;
            }
        }
    }


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值