コード例 #1
0
ファイル: Index.aspx.cs プロジェクト: lfc1994/SupermarketWeb
        //用户登录
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            lblUserIdTip.Text = string.Empty;
            lblPwdTip.Text    = string.Empty;
            lblmsg.Text       = string.Empty;

            if (txtUserId.Text == string.Empty)
            {
                //Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('请输入用户名?');</script>");
                // lblUserIdTip.BackColor = System.Drawing.Color.FromArgb(255, 180, 180);
                lblUserIdTip.Text      = "亲,没有输入帐号哟? ";
                lblUserIdTip.Font.Name = "STHUPO";
                lblUserIdTip.Font.Size = 15;
            }
            else if (txtPwd.Text == string.Empty)
            {
                lblPwdTip.Text      = "=。=还没有密码呢 ";
                lblPwdTip.Font.Name = "STHUPO";
                lblPwdTip.Font.Size = 15;
            }
            else
            {
                ComUserInfo item = ComUserInfoDAL.CheckUserLogin(ComClass.NoHTML(txtUserId.Text), ComClass.NoHTML(txtPwd.Text));
                if (item == null)
                {
                    lblmsg.Text      = "阿欧!账号或者密码不对哟";
                    lblmsg.Font.Name = "STHUPO";
                    lblmsg.Font.Size = 15;
                }
                else
                {
                    if (item.UserId == txtUserId.Text && item.LoginPwd == txtPwd.Text)             //通过等号表达式判断账号密码的大小写是否正确
                    {
                        Session["LoginedUser"] = item;                                             //以键来存储当前已登录用户对象
                        //发放令牌
                        System.Web.Security.FormsAuthentication.SetAuthCookie(item.UserId, false); //在服务器端保存一个用户身份的凭证
                        //向日志数据库写入日志信息,当前用户的IP地址是哪里登录进来的(可用于用户验证自己的账号是否被盗用)
                        //更新当前登录用户最近一次登录IP和登录日期
                        bool flag = ComUserInfoDAL.UpdateLatestIpDate(item.UserId, Request.UserHostAddress, DateTime.Now);
                        lblUserId.Visible      = false; txtUserId.Visible = false;
                        txtPwd.Visible         = false; lblPwd.Visible = false;
                        lblUserIdTip.Text      = "欢迎光临!!!";
                        lblUserIdTip.Font.Name = "STHUPO";
                        lblUserIdTip.Font.Size = 17;
                        lblPwdTip.Text         = "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp亲爱的:" + item.UserName;
                        lblPwdTip.Font.Name    = "STHUPO";
                        lblPwdTip.Font.Size    = 17;
                        btnLogin.Visible       = false; btnReset.Visible = false;
                        // lblmsg.Text = "真棒  = 。 =";
                    }
                    else
                    {
                        lblmsg.Text      = "哎呀~大小写错咯!";
                        lblmsg.Font.Name = "STHUPO";
                        lblmsg.Font.Size = 15;
                    }
                }
            }
        }
コード例 #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserId.Text == string.Empty)
            {
                lbltp.Text = "请输入帐号?";
                txtUserId.Focus();
            }
            else if (txtPwd.Text == string.Empty)
            {
                lbltp.Text = string.Empty;
                txtPwd.Focus();
                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 请输入密码? ');</script>");
            }
            else if (txtVerifycode.Text == string.Empty)
            {
                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 请输入验证码? ');</script>");
                txtVerifycode.Focus();
            }
            else
            {
                string verfiycode = string.Empty;
                if (Session["VerifyCodeAdmin"] != null)
                {
                    verfiycode = (string)Session["VerifyCodeAdmin"];
                    if (txtVerifycode.Text.ToLower() != verfiycode.ToLower())
                    {
                        HttpContext.Current.Response.Write("<script language='javascript'>alert(' 验证码输入错误! ');</script>");
                    }
                    else
                    {
                        //查询数据校验帐号和密码
                        //查询之前先加密密码再与数据库中的密码比对
                        string     adminPwd = ComClass.TripleDESEncryptString(txtPwd.Text);
                        AdUserInfo item     = AdUserInfoDAL.CheckUserLogin(
                            ComClass.NoHTML(txtUserId.Text), adminPwd);
                        if (item == null)
                        {
                            HttpContext.Current.Response.Write("<script language='javascript'>alert(' 输入错误,未通过验证!');</script>");
                        }
                        else
                        {
                            if (item.AdminUserId == txtUserId.Text)
                            {
                                Session["LoginedAdmin"] = item;

                                //发放令牌
                                System.Web.Security.FormsAuthentication.SetAuthCookie(item.AdminUserId, false);

                                //跳转页面
                                Response.Redirect("~/Admin/ProductManageList.aspx");
                            }
                            else
                            {
                                HttpContext.Current.Response.Write("<script language='javascript'>alert(' 注意大小写!');</script>");
                            }
                        }
                    }
                }
                else
                {
                    HttpContext.Current.Response.Write("<script language='javascript'>alert(' 服务生成验证码出错! ');</script>");
                }
            }
        }