示例#1
0
        public ActionResult Login(string userName, string password)
        {
            var user        = _userDbContext.FindByEmail(userName);
            var md5Password = CalculateMD5Hash(password);

            if (user == null || !user.Password.Equals(md5Password) || !user.IsActive)
            {
                TempData["hasErrors"] = true;
                return(RedirectToAction("Index", "Home"));
            }

            HttpCookie cookie = new HttpCookie("userId");

            cookie.Value   = user.Id.ToString();
            cookie.Expires = DateTime.Now.AddDays(1);
            Response.Cookies.Add(cookie);

            return(RedirectToAction("Index", "Configuration"));
        }
示例#2
0
        public ActionResult Login(string userName, string password)
        {
            var users = _userDbContext.FindByEmail(userName);

            if (users.Count() == 0)
            {
                ViewData["hasErrors"] = true;
                return(View("Index"));
            }

            var md5Password = CalculateMD5Hash(password);
            var user        = users.Where(x => x.Password.Equals(md5Password)).FirstOrDefault();

            if (user == null)
            {
                ViewData["hasErrors"] = true;
                return(View("Index"));
            }

            return(RedirectToAction("Index", "Configuration"));
        }