public bool Validate(LoginViewModel logIn) { // Look up attorney var attorneyQuery = from a in db.User where a.User_Code == logIn.Code select new { Attorney_Code = a.User_Code, a.Hashed_Password, }; // Run query var attorney = attorneyQuery.SingleOrDefault(); // Did we find the username? if (attorney != null) { // Check password return BCrypt.Net.BCrypt.Verify(logIn.Password, attorney.Hashed_Password); } else { return false; } }
public ActionResult Login(string ReturnUrl, LoginViewModel logIn) { if (ModelState.IsValid) { bool valid = userService.Validate(logIn); if (valid) { // Set cookie with user code (look in Application_PostAuthenticateRequest to see how we use this later) FormsAuthentication.SetAuthCookie(logIn.Code, true); // Send home return RedirectToAction("Index", "Home"); } } return View(); }