Ejemplo n.º 1
0
 public bool Login(LoginModel login)
 {
     string userStatus = LocalNewsConstant.User_Status_Login;
     if (login == null)
     {
         throw new ArgumentNullException("user");
     }
     User user = null;
     string password = CryptoUtil.ComputeHash(login.Password);
     using (var db = new LocalNewsDBEntities())
     {
         user = db.Users.Where(u => u.username == login.UserName && u.password == password).FirstOrDefault();
     }
     if (null == user)
     {
         user = Get(login.UserName);
         userStatus = LocalNewsConstant.User_Status_Wrong_Password;
         return false;
     }
     loginHistoryBll.Add(user.user_id, userStatus);
     return true;
 }
Ejemplo n.º 2
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid && userBll.Login(model))
            {
                FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                return RedirectToLocal(returnUrl);
            }

            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "The user name or password provided is incorrect.");
            return View(model);
        }