public ActionResult AutenticarUsuario(UsuarioModelLogin model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UsuarioDal d = new UsuarioDal();
                    Usuario u = d.Find(model.Login, Criptografia.EncriptarMD5(model.Senha));

                    if (u != null)
                    {
                        FormsAuthentication.SetAuthCookie(u.Login, false);

                        Session.Add("usuario", u);

                        return RedirectToAction("Home", "UsuarioAutenticado");

                    }
                    else
                    {
                        ViewBag.Mensagem = "Acesso Negado. Tente Novamente.";
                    }
                }

            }
            catch (Exception ex)
            {
                ViewBag.Mensagem = ex.Message;
            }

            return View("Login");
        }
示例#2
0
        protected void btnAcesso_Click(object sender, EventArgs e)
        {
            try
            {

                string login = txtLogin.Text;
                string senha = txtSenha.Text;

                UsuarioDal d = new UsuarioDal();
                Usuario u = d.Find(login, Criptografia.Encriptar(senha));

                if (u!= null)
                {
                    FormsAuthentication.SetAuthCookie(login, false);

                    Response.Redirect("/Pages/Produto.aspx");
                }

            }
            catch (Exception ex)
            {

                lblMensagem.Text = ex.Message;
            }
        }