public IActionResult Send2FA(TwoFactorAuth model) { TwoFactorAuthenticator TwoFacAuth = new TwoFactorAuthenticator(); string UserUniqueKey = TempData["UserUniqueKey"].ToString(); bool isValid = TwoFacAuth.ValidateTwoFactorPIN(UserUniqueKey, model.CodeDigit.ToString()); if (isValid) { HttpContext.Session.SetString("IsValidTwoFactorAuthentication", "true"); HttpContext.Session.SetString("LoginID", TempData["LoginID"].ToString()); HttpContext.Session.SetString("LoginEmail", TempData["LoginEmail"].ToString()); User userLoggedIn = _context.GetUser(Convert.ToInt32(HttpContext.Session.GetString("LoginID"))); _context.LogAction("2 Factor Authentication", "Authentication successful.", userLoggedIn); if (userLoggedIn.UserRole == "Admin") { HttpContext.Session.SetString("AdminValidity", "Admin"); } else if (userLoggedIn.UserRole == "Super Admin") { HttpContext.Session.SetString("AdminValidity", "Super Admin"); } if (userLoggedIn.Authenticated == false) { _context.SetUserAsAuthenticated(HttpContext.Session.GetString("LoginEmail")); } return(RedirectToAction("Profile", "Users")); } else { ViewBag.Message = "Invalid code entered, please try again."; string email = TempData["LoginEmail"].ToString(); TempData["LoginEmail"] = email; UserUniqueKey = (email + GoogleAuthKey); TempData["UserUniqueKey"] = UserUniqueKey; //Session User userLoggingIn = _context.GetUserByEmail(email); _context.LogAction("2 Factor Authentication", "Authentication failure. Invalid code entered.", userLoggingIn); return(View("Send2FA")); } }