コード例 #1
0
        //检查用户登录账号和密码
        public static ComUserInfo CheckUserLogin(string userId, string pwd)
        {
            string      sqlString = "select * from dbo.ComUserInfo where UserId=@UserId and LoginPwd=@LoginPwd";
            ComUserInfo item      = null;

            //参数列表
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@UserId", userId),
                new SqlParameter("@LoginPwd", pwd)
            };
            try
            {
                using (SqlDataReader reader = SQLHelper.GetReader(sqlString, parms))
                {
                    if (reader.Read() && !reader.IsClosed)
                    {
                        item = new ComUserInfo(reader);
                    }
                    reader.Close();//关闭reader
                }
            }
            catch (Exception e)
            { }
            return(item);
        }
コード例 #2
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;
                    }
                }
            }
        }