public ActionResult Login(LoginModel entity) { string OldHASHValue = string.Empty; byte[] SALT = new byte[Common.saltLengthLimit]; try { using (db = new BootstrapMVCEntities()) { // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { return(View(entity)); } //Retrive Stored HASH Value From Database According To Username (one unique field) var userInfo = db.users.Where(s => s.U_Name == entity.Username.Trim()).FirstOrDefault(); //Assign HASH Value if (userInfo != null) { OldHASHValue = userInfo.U_Password; } bool isLogin = CompareHashValue(entity.Password, OldHASHValue); if (isLogin) { //Login Success //For Set Authentication in Cookie (Remeber ME Option) SignInRemember(entity.Username, entity.isRemember); //Set A Unique ID in session Session["UserID"] = userInfo.U_ID; // If we got this far, something failed, redisplay form // return RedirectToAction("Index", "Dashboard"); return(RedirectToLocal(entity.ReturnURL)); } else { //Login Fail TempData["ErrorMSG"] = "Access Denied! Please Try Again"; return(View(entity)); } } } catch { throw; } }