public JsonResult Unlock(string code) { // IP адрес пользователя string IP = HttpContext.Connection.RemoteIpAddress.ToString(); // Проверка кода GoogleTo2FA TwoFacAuth = new GoogleTo2FA(); if (TwoFacAuth.ValidateTwoFactorPIN(PasswdTo.Google2FA, code)) { // Берем сессию из кук if (HttpContext.Request.Cookies.TryGetValue("authSession", out string authSession)) { // Текущая сессия if (coreDB.Auth_Sessions.FindItem(i => i.Session == authSession, TrackingType.Tracking) is AuthSession item) { // 2FA пройдена item.Confirm2FA = true; coreDB.SaveChanges(); // Trigger.OnTwoFacAuth((IP, IsSuccess: true)); // Успех return(Json(new TrueOrFalse(true))); } } } // Trigger.OnTwoFacAuth((IP, IsSuccess: false)); // Ошибка return(Json(new Text("Неверный код"))); }
public IActionResult Index(bool ajax) { GoogleTo2FA TwoFacAuth = new GoogleTo2FA(); var setupInfo = TwoFacAuth.GenerateSetupCode("ISPCore", HttpContext.Request.Host.Host, PasswdTo.Google2FA, 300, 300, useHttps: true); ViewBag.BarcodeImageUrl = setupInfo.QrCodeSetupImageUrl; ViewData["salt"] = PasswdTo.salt; ViewData["ajax"] = ajax; return(View("/Views/Settings/Base.cshtml", jsonDB)); }