public ActionResult AutenticarFuncionario(FuncionarioModelLogin model) { try { if (ModelState.IsValid) { FuncionarioDal d = new FuncionarioDal(); Funcionario f = d.Authenticate(model.Login, Criptografia.GetMD5Hash(model.Senha)); if(f != null) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(f.Login, model.ManterConectado, 5); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); Response.Cookies.Add(cookie); Session.Add("funcionariologado", f); return RedirectToAction("Index", "Default", new {area = "Admin"}); } else { ViewBag.Mensagem = "Acesso Negado."; } } } catch (Exception e) { ViewBag.Mensagem = e.Message; } return View("Login"); }
protected void btnLogin_Click(object sender, EventArgs e) { try { FuncionarioDal d = new FuncionarioDal(); Funcionario f = d.Authenticate(txtLogin.Text, txtSenha.Text); if(f != null) { FormsAuthentication.SetAuthCookie(f.Login, checkLogin.Checked); Session.Add("Funcionario", f); Response.Redirect("/Admin/Default.aspx"); } else { throw new Exception("Acesso Negado, Tente novamente."); } } catch (Exception ex) { lblMensagem.Text = ex.Message; } }