示例#1
0
 public ActionResult AutenticarUsuario(Usuario usuario)
 {
     if (_bll.AutenticarUsuario(usuario.login, usuario.senha))
     {
         return(RedirectToAction("Index", "Loja")); //Autenticado com sucesso redireciona para pagina principal
     }
     else
     {
         ViewBag.MensagemErro = "O nome de usuário ou senha estão incorretos";
         return(RedirectToAction("Index", "Login"));
     }
 }
示例#2
0
        private async void LogarUsuario()
        {
            if (ValidacaoCampos())
            {
                Usuario usuario = new Usuario();

                usuario.NomeUsuario  = txt_login.Text;
                usuario.PalavraPasse = txt_senha.Text;
                usuario = usuarioBLL.AutenticarUsuario(usuario);
                if (usuario != null)
                {
                    MessageBox.Show($"User Name: {usuario.NomeUsuario} Password BD: {usuario.PalavraPasse} + ");
                    //MessageBox.Show($"{criptoMD5.ComparaMD5(txt_senha.Text, usuario.PalavraPasse)}\n - {criptoMD5.RetornarMD5(txt_senha.Text)} \n-  { usuario.PalavraPasse}");
                }

                if (txt_login.Text == "Moises" && txt_senha.Text == "123#")
                {
                    VisualSucesso("Moises");
                    await Task.Delay(2000);

                    txt_login.Text  = "";
                    txt_senha.Text  = "";
                    this.Visibility = Visibility.Hidden;
                    MainWindow main = new MainWindow();
                    main.ShowDialog();
                }
                else if (usuario != null && usuario.NomeUsuario.Equals(txt_login.Text) && txt_senha.Text.Equals(usuario.PalavraPasse))
                {
                    VisualSucesso(usuario.NomeUsuario);
                    await Task.Delay(2000);

                    txt_login.Text = "";
                    txt_senha.Text = "";
                    MainWindow main = new MainWindow(usuario);
                    this.Close();
                    main.ShowDialog();
                }
                else
                {
                    AlteracaoVisualErro("O Nome de Utilizador e a Palavra-Passe não coincidem");
                }
            }
        }
示例#3
0
        protected void AutenticarUsuario(string Identificacion, string Password)
        {
            #region "Definitions"
            int        UsuarioID;
            UsuarioBLL objUsuarioBLL;
            #endregion
            #region "try"
            try
            {
                #region "Objects Instance"
                UsuarioID     = 0;
                objUsuarioBLL = new UsuarioBLL();
                #endregion

                FormsAuthentication.Initialize();
                UsuarioID = objUsuarioBLL.AutenticarUsuario(txtIdentificacion.Text.Trim(), txtPassword.Text.Trim());

                if (UsuarioID != 0)
                {
                    string TiempoCookie = ConfigurationManager.AppSettings["TiempoCookie"];

                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, UsuarioID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(double.Parse(TiempoCookie)), false, string.Empty, FormsAuthentication.FormsCookiePath);
                    string     hash   = FormsAuthentication.Encrypt(ticket);
                    HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
                    Response.Cookies.Add(cookie);
                    Response.Redirect(Page.Request.Path);
                }
            }
            #endregion
            #region "catch"
            catch (Exception ex)
            {
                General.MostrarAlerta(this.Page, ex.Message);
            }
            #endregion
            #region "finally"
            finally
            {
                objUsuarioBLL = null;
                GC.Collect();
            }
            #endregion
        }
示例#4
0
        private void Logar()
        {
            try
            {
                if (txtNome.Text == "" || txtSenha.Password == "")
                {
                    this.ShowMessageAsync("Alerta", "Preencha os campos para continuar");
                }
                else
                {
                    UsuarioDTO user    = new UsuarioDTO();
                    UsuarioBLL userbll = new UsuarioBLL();

                    user.Login1 = txtNome.Text;
                    user.Senha  = criptografar(txtSenha.Password);
                    user.Nivel  = "Gerente";
                    user        = userbll.AutenticarUsuario(user);
                    if (user.Login1 == null && user.Senha == null)
                    {
                        this.ShowMessageAsync("Alerta", "Dados invalidos!");
                    }
                    else
                    {
                        MainWindow mn = new MainWindow();
                        mn.nivel = 0;
                        this.ShowMessageAsync("Boas vindas!", "Bem vindo " + txtNome.Text);
                        mn.lblNome.Content = "Bem vindo " + txtNome.Text + "!";

                        mn.Show();
                        this.Hide();
                    }
                }
                if (txtNome.Text == "" || txtSenha.Password == "")
                {
                    this.ShowMessageAsync("Alerta", "Preencha os campos para continuar");
                }
                else
                {
                    UsuarioDTO user    = new UsuarioDTO();
                    UsuarioBLL userbll = new UsuarioBLL();

                    user.Login1 = txtNome.Text;
                    user.Senha  = criptografar(txtSenha.Password);
                    user.Nivel  = "Diretor";
                    user        = userbll.AutenticarUsuario(user);
                    if (user.Login1 == null && user.Senha == null)
                    {
                        this.ShowMessageAsync("Alerta", "Dados invalidos!");
                    }
                    else
                    {
                        MainWindow mn = new MainWindow();
                        mn.nivel = 1;
                        this.ShowMessageAsync("Boas vindas!", "Bem vindo " + txtNome.Text);
                        mn.lblNome.Content = "Bem vindo " + txtNome.Text + "!";

                        mn.Show();
                        this.Hide();
                    }
                }
                if (txtNome.Text == "" || txtSenha.Password == "")
                {
                    this.ShowMessageAsync("Alerta", "Preencha os campos para continuar");
                }
                else
                {
                    UsuarioDTO user    = new UsuarioDTO();
                    UsuarioBLL userbll = new UsuarioBLL();

                    user.Login1 = txtNome.Text;
                    user.Senha  = criptografar(txtSenha.Password);
                    user.Nivel  = "Presidente";
                    user        = userbll.AutenticarUsuario(user);
                    if (user.Login1 == null && user.Senha == null)
                    {
                        this.ShowMessageAsync("Alerta", "Dados invalidos!");
                    }
                    else
                    {
                        MainWindow mn = new MainWindow();
                        mn.nivel = 1;
                        this.ShowMessageAsync("Boas vindas!", "Bem vindo " + txtNome.Text);
                        mn.lblNome.Content = "Bem vindo " + txtNome.Text + "!";

                        mn.Show();
                        this.Hide();
                    }
                }
                if (txtNome.Text == "" || txtSenha.Password == "")
                {
                    this.ShowMessageAsync("Alerta", "Preencha os campos para continuar");
                }
                else
                {
                    UsuarioDTO user    = new UsuarioDTO();
                    UsuarioBLL userbll = new UsuarioBLL();

                    user.Login1 = txtNome.Text;
                    user.Senha  = criptografar(txtSenha.Password);
                    user.Nivel  = "Recepcao";
                    user        = userbll.AutenticarUsuario(user);
                    if (user.Login1 == null && user.Senha == null)
                    {
                        this.ShowMessageAsync("Alerta", "Dados invalidos!");
                    }
                    else
                    {
                        MainWindow mn = new MainWindow();
                        mn.nivel = 2;
                        this.ShowMessageAsync("Boas vindas!", "Bem vindo " + txtNome.Text);
                        mn.lblNome.Content = "Bem vindo " + txtNome.Text + "!";

                        mn.Show();
                        this.Hide();
                    }
                }
            }


            catch (Exception erro)
            {
                this.ShowMessageAsync("Erro", "Usuario ou senha invalidos" + erro);
            }
        }