public ActionResult Login(LoginCredentialModel loginCredentials) { UserProcess userProcessor = new UserProcess(); if (ModelState.IsValid) { int result = userProcessor.LoginUser(loginCredentials.Username, MD5HashProvider.CreateMD5Hash(loginCredentials.Password)); if (result == FASTConstant.RETURN_VAL_SUCCESS) { // set the forms auth cookie FormsAuthentication.SetAuthCookie(loginCredentials.Username.ToString(), false); // reset request.isauthenticated var authCookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); if (authTicket != null && !authTicket.Expired) { var roles = authTicket.UserData.Split(','); System.Web.HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(new FormsIdentity(authTicket), roles); } } return(RedirectToAction("MyAssets", "Home")); } else { ModelState.AddModelError("", "Wrong Employee Employee ID or Password"); } } return(View()); }
public void TestLogin() { int expected = FASTConstant.RETURN_VAL_SUCCESS; Repository.UnitsOfWork.GenericUnitOfWork <Registration> reg = new Repository.UnitsOfWork.GenericUnitOfWork <Registration>(); Registration result = reg.Repository.GetAllQueryable().Where(m => m.EmployeeID == 114560).First(); int actual = _userProcess.LoginUser(114560, result.Password); Assert.AreEqual(expected, actual); }