private bool ValidaUsuario(string loginUsuario, string senhaUsuario)
        {
            try
            {
                Entidades.Usuario          u        = new Entidades.Usuario();
                List <Entidades.Usuario>   lRetUser = new List <Entidades.Usuario>();
                Negocios.Cadastro.Usuarios n        = new Negocios.Cadastro.Usuarios();

                u.LoginUsuario = loginUsuario.Trim().ToUpper();
                u.SenhaUsuario = senhaUsuario.Trim().ToUpper();

                lRetUser = n.Listar(u);

                if (lRetUser.Count > 0 && lRetUser.FirstOrDefault().FlagAtivo.Equals("S"))
                {
                    Session.Add("ws_siscom_acesso", lRetUser.FirstOrDefault());
                    Session.Add("ws_siscom_login", lRetUser.FirstOrDefault().LoginUsuario);
                    Session.Add("ws_siscom_senha", senhaUsuario);

                    return(true);
                }

                return(false);
            }
            catch (Exception ex)
            { throw ex; }
        }
Пример #2
0
        protected void btnSalvarSenha_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtSenhaAtual.Text.Trim().Length == 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('Informe a senha atual');</script>", false);
                    return;
                }
                else if (txtNovaSenha.Text.Trim().Length == 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('Informe a nova senha');</script>", false);
                    return;
                }
                else if (txtConfirmaNovaSenha.Text.Trim().Length == 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('Informe a confirmação da nova senha');</script>", false);
                    return;
                }
                else if (!txtConfirmaNovaSenha.Text.ToUpper().Trim().Equals(txtNovaSenha.Text.Trim().ToUpper()))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('A CONFIRMAÇÃO e a NOVA SENHA devem ser iguais');</script>", false);
                    return;
                }


                Util.Cryptography cript      = new Util.Cryptography(Util.EncryptionAlgorithm.TripleDes);
                string            SenhaCript = "";
                SenhaCript = Convert.ToBase64String(cript.Encrypt(Encoding.ASCII.GetBytes(txtSenhaAtual.Text.ToUpper()), Util.Cryptography.Key, Util.Cryptography.Vector));

                if (!usuarioLogado.SenhaUsuario.Equals(SenhaCript))
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('A senha atual esta incorreta.');</script>", false);
                    return;
                }

                Negocios.Cadastro.Usuarios negUsu        = new Negocios.Cadastro.Usuarios();
                Entidades.Usuario          userAlteracao = new Entidades.Usuario();

                userAlteracao.SenhaUsuario = Convert.ToBase64String(cript.Encrypt(Encoding.ASCII.GetBytes(txtNovaSenha.Text.ToUpper()), Util.Cryptography.Key, Util.Cryptography.Vector));;
                userAlteracao.IdUsuario    = usuarioLogado.IdUsuario;

                bool retAlteracao = negUsu.AlterarSenha(usuarioLogado.IdUsuario, userAlteracao);

                if (retAlteracao)
                {
                    usuarioLogado.SenhaUsuario = SenhaCript;
                    Session["UsuarioLogado"]   = usuarioLogado;
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('Senha alterada com sucesso.');</script>", false);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "msgAlerta", "<script>alert('A senha não foi alterada. Entrem em contato com o administrador do sistema.');</script>", false);
                }
            }
            catch (Exception ex)
            {
                Util.Log.Save("ex:" + ex.Message, "btnSalvarSenha_Click", nomeModuloLog, HttpContext.Current.Server.MapPath(diretorioLog));
            }
        }
Пример #3
0
        private bool Acesso()
        {
            try
            {
                Entidades.Usuario          u        = new Entidades.Usuario();
                List <Entidades.Usuario>   lRetUser = new List <Entidades.Usuario>();
                Negocios.Cadastro.Usuarios n        = new Negocios.Cadastro.Usuarios();

                u.LoginUsuario = txtLoginUsuario.Text.Trim().ToUpper();
                u.SenhaUsuario = txtSenhaUsuario.Text.Trim().ToUpper();

                if (!VerificaSessionAutenticacao(u.LoginUsuario, u.SenhaUsuario))
                {
                    lRetUser = n.Listar(u);

                    if (lRetUser.Count > 0 && lRetUser.FirstOrDefault().FlagAtivo.Equals("S"))
                    {
                        bool temPerfil = false;

                        //verifica se o usuario tem o perfil de acesso necessario
                        for (int i = 0; i < lRetUser.FirstOrDefault().Perfil.Count; i++)
                        {
                            if (lRetUser.FirstOrDefault().Perfil[i].DescricaoPerfilAcesso.ToUpper().Trim().Equals("CLIENTE SITE") ||
                                lRetUser.FirstOrDefault().Perfil[i].DescricaoPerfilAcesso.ToUpper().Trim().Equals("ADMINISTRADOR"))
                            {
                                this.Session.Add("UsuarioLogado", lRetUser.FirstOrDefault());
                                temPerfil = true;
                            }
                        }

                        if (!temPerfil && this.Session != null)
                        {
                            this.Session.Abandon();
                            return(false);
                        }
                    }
                    else
                    {
                        this.Session.Abandon();
                        //lblLoginUsuario.Text = "";
                        //lblNumeroIPCliente.Text = "";
                        //lblDataAtual.Text = "";
                    }
                }

                return(lRetUser.Count > 0);
            }
            catch (Exception ex)
            { throw ex; }
        }