Esempio n. 1
0
 public ActionResult LoginButton(string id, string senha)
 {
     if (ModelState.IsValid)
     {
         if (id == "admin")
         {
             using (MD5 md5Hash = MD5.Create())
             {
                 if (MyHelpers.VerifyMd5Hash(md5Hash, senha, "21232f297a57a5a743894a0e4a801fc3"))
                 {
                     HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(id, "admin", 30);
                     Response.Cookies.Add(cookie);
                 }
                 else
                 {
                     ModelState.AddModelError("password", "Password incorreta!");
                     return(View("Login"));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "Dados incorretos. Tente novamente.");
             return(View("Login"));
         }
     }
     else
     {
         ModelState.AddModelError("", "Invalid Request");
         return(View("Login"));
     }
     return(RedirectToAction("loginSucess", "Admin"));
 }
 public ActionResult Login(string email, string password)
 {
     if (ModelState.IsValid)
     {
         var clientes = (from c in db.Clientes
                         where c.email == email
                         select c);
         if (clientes.ToList <Cliente>().Count > 0)
         {
             Cliente cliente = clientes.ToList <Cliente>().ElementAt <Cliente>(0);
             using (MD5 md5Hash = MD5.Create())
             {
                 if (MyHelpers.VerifyMd5Hash(md5Hash, password, cliente.password))
                 {
                     HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(cliente.nif_cliente.ToString(), "user", 30);
                     Response.Cookies.Add(cookie);
                 }
                 else
                 {
                     ModelState.AddModelError("password", "Password incorreta!");
                     return(View("Index"));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "Dados incorretos. Tente novamente.");
             return(View("Index"));
         }
     }
     else
     {
         ModelState.AddModelError("", "Invalid Request");
         return(View("Index"));
     }
     return(RedirectToAction("loginSucess", "Login"));
 }
 public ActionResult LoginButton(int id, string password)
 {
     if (ModelState.IsValid)
     {
         var funcionarios = (from f in db.Funcionarios
                             where f.id_funcionario == id
                             select f);
         if (funcionarios.ToList <Funcionario>().Count > 0)
         {
             Funcionario funcionario = funcionarios.ToList <Funcionario>().ElementAt <Funcionario>(0);
             using (MD5 md5Hash = MD5.Create())
             {
                 if (MyHelpers.VerifyMd5Hash(md5Hash, password, funcionario.password))
                 {
                     HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(funcionario.id_funcionario.ToString(), "staff", 10);
                     Response.Cookies.Add(cookie);
                 }
                 else
                 {
                     ModelState.AddModelError("password", "Password incorreta!");
                     return(View("Index"));
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "Dados incorretos. Tente novamente.");
             return(View("Index"));
         }
     }
     else
     {
         ModelState.AddModelError("", "Invalid Request");
         return(View("Index"));
     }
     return(RedirectToAction("loginSucess", "Mobile"));
 }
Esempio n. 4
0
        public ActionResult Login(string username, string password)
        {
            DefaultController.Funcionario           = new Funcionario();
            DefaultController.Funcionario.Pass_word = password;
            int userName = Int32.Parse(username);

            if (ModelState.IsValid)
            {
                var userC = (from m in db.Cliente where (m.Id == userName) select m);

                if (userC.ToList().Count > 0)
                {
                    Cliente cliente = userC.ToList().ElementAt <Cliente>(0);
                    using (MD5 md5Hash = MD5.Create())
                    {
                        if (MyHelpers.VerifyMd5Hash(md5Hash, password, cliente.Pass_word))
                        {
                            string     client = cliente.Id.ToString();
                            HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(cliente.Id.ToString(), cliente.Role);
                            Response.Cookies.Add(cookie);
                            ViewData["User_Name"] = "Bem vindo" + cliente.Nome;
                            return(RedirectToAction("Index", "Cliente"));
                        }
                        else
                        {
                            ModelState.AddModelError("password", "Password incorreta!");
                            return(View());
                        }
                    }
                }
                else
                {
                    var userF = (from m in db.Funcionario where (m.Id == userName) select m);
                    if (userF.ToList().Count > 0)
                    {
                        Funcionario funcionario = userF.ToList().ElementAt <Funcionario>(0);
                        using (MD5 md5Hash = MD5.Create())
                        {
                            if (MyHelpers.VerifyMd5Hash(md5Hash, password, funcionario.Pass_word))
                            {
                                string     func   = funcionario.Id.ToString();
                                HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(funcionario.Id.ToString(), funcionario.Role);
                                Response.Cookies.Add(cookie);
                                if (funcionario.Role.Equals("func"))
                                {
                                    ViewData["User_Name"] = "Bem vindo" + funcionario.Nome;
                                    return(RedirectToAction("Index", "Funcionario"));
                                }
                                else
                                {
                                    var t = ViewData["User_Name"] = "Bem vindo" + funcionario.Nome;
                                    return(RedirectToAction("Index", "Admin"));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("password", "Password incorreta!");
                                return(View());
                            }
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Login data is incorrect!");
                        return(View());
                    }
                }
            }
            return(View());
        }
Esempio n. 5
0
        public ActionResult Login(string Username, string Password)
        {
            if (ModelState.IsValid)
            {
                var clientes = (from m in db.Clientes
                                where m.Username == Username
                                select m);

                if (clientes.ToList <Cliente>().Count == 0)
                {
                    var funcionarios = (from m in db.Funcionarios
                                        where m.Username == Username
                                        select m);

                    if (funcionarios.ToList <Funcionario>().Count > 0)
                    {
                        Funcionario funcionario = funcionarios.ToList <Funcionario>().ElementAt <Funcionario>(0);
                        using (MD5 md5Hash = MD5.Create())
                        {
                            if (MyHelpers.VerifyMd5Hash(md5Hash, Password, funcionario.Password))
                            {
                                HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(funcionario.Username, funcionario.Role);
                                Response.Cookies.Add(cookie);
                                if (Username.Equals("admin"))
                                {
                                    return(RedirectToAction("Index", "Admin"));
                                }
                                else
                                {
                                    return(RedirectToAction("Index", "Funcionario"));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("password", "Password incorreta!");
                                return(View("Index"));
                            }
                        }
                    }
                }
                else
                {
                    Cliente cliente = clientes.ToList <Cliente>().ElementAt <Cliente>(0);
                    using (MD5 md5Hash = MD5.Create())
                    {
                        if (MyHelpers.VerifyMd5Hash(md5Hash, Password, cliente.Password))
                        {
                            HttpCookie cookie = MyHelpers.CreateAuthorizeTicket(cliente.Username, cliente.Role);
                            Response.Cookies.Add(cookie);
                            return(RedirectToAction("Index", "Cliente"));
                        }
                        else
                        {
                            ModelState.AddModelError("password", "Password incorreta!");
                            return(View("Index"));
                        }
                    }
                }
            }
            ModelState.AddModelError("", "Username incorreto!");
            return(View("Index"));
        }