public ActionResult Login(User u) { // this action is for handle post (login) if (ModelState.IsValid) // this is check validity { using (IMS_V1Entities db = new IMS_V1Entities()) { var v = db.Users.Where(a => a.UserName.Equals(u.UserName)).FirstOrDefault(); // && a.Password.Equals(u.Password)).FirstOrDefault(); if (v != null) { byte[] enPwd = GetSHA1(v.UserName, u.Password); if (MatchSHA1(enPwd, v.EncryptPwd) && (v.Active != null && v.Active.Value)) { Session.Add("UserID", v.User_id); Session.Add("UserTypeID", v.UserType_Id); Session.Add("LogedUserFullName", v.FirstName.ToString() + " " + v.LastName.ToString()); Session.Add("Logout", "false"); //Session.Add("CreateAPlusImport", v.CreateAPlusImport_MarineShooting); int usertypeid = int.Parse(Session.Contents["UserTypeId"].ToString()); if (usertypeid == 2) { return(RedirectToAction("Index", "Item")); } else { return(RedirectToAction("Index", "Home")); } } else { Session.Add("LogedUserFullName", ""); Session.Add("Logout", "true"); return(RedirectToAction("Login", new { Login = 1, ErrorMessage = "UserName or Password is incorrect. Please try again." })); } } else { Session.Add("LogedUserFullName", ""); Session.Add("Logout", "true"); return(RedirectToAction("Login", new { Login = 1, ErrorMessage = "UserName or Password is incorrect. Please try again." })); } } } return(View(u)); }