Пример #1
0
    protected void imgBtnLogin_Click(object sender, EventArgs e)
    {
        string DBPassword;
        bool   SuccessLogin = false;
        string Username     = txtUsername.Text;
        string Password     = txtPassword.Text;

        //UsersBR bolUsers = new UsersBR();


        if (chkRemInfo.Checked)
        {
            Response.Cookies["Khabardaan"].Expires           = DateTime.Now.AddDays(30);
            Response.Cookies["Khabardaan"]["KhabardaanUser"] = txtUsername.Text;

            Response.Cookies["Khabardaan"].Expires           = DateTime.Now.AddDays(30);
            Response.Cookies["Khabardaan"]["KhabardaanPass"] = txtPassword.Text;
        }
        else
        {
            Response.Cookies["Khabardaan"].Expires           = DateTime.Now.AddDays(30);
            Response.Cookies["Khabardaan"]["KhabardaanUser"] = "";

            Response.Cookies["Khabardaan"].Expires           = DateTime.Now.AddDays(30);
            Response.Cookies["Khabardaan"]["KhabardaanPass"] = "";
        }

        Users ValidUser = BOLUsers.GetDataByUsername(Username);

        if (ValidUser != null)
        {
            string HashedPass = Tools.GetHashString(txtPassword.Text);
            DBPassword = ValidUser.Password;
            if (HashedPass == DBPassword && (bool)ValidUser.Active)
            {
                BOLUsers.UpdateLastLoginTime(ValidUser.Code);
                SuccessLogin = true;
                LoginUser(ValidUser);
            }
            else
            {
                SuccessLogin = false;
            }
        }
        else
        {
            SuccessLogin = false;
        }

        if (!SuccessLogin)
        {
            msgBox.Text = Messages.ShowMessage(MessagesEnum.InvalidLogin);
        }
    }