public ActionResult ShowTwoFactorSecret(ShowTwoFactorSecretViewModel model) { using (var db = new MembershipContext()) { User user = db.Users.Single(u => u.UserId == WebSecurity.CurrentUserId); if (TwoFactorPasswordGenerator.GenerateTimeBasedPassword(user.TwoFactorSecret) != model.TwoFactorCode) { ModelState.AddModelError("TwoFactorCode", "The Code is not valid"); model.SecretKey = Base32.Base32Encoder.Encode(System.Text.Encoding.ASCII.GetBytes(user.TwoFactorSecret)); user.IsGoogleAuthenticatorEnabled = model.EnableTwoFactorAuthentication = false; return View(model); } else { user.IsGoogleAuthenticatorEnabled = true; } db.SaveChanges(); } return RedirectToAction("Index", "Home"); }
// // GET: /Account/ShowTwoFactorSecret public ActionResult ShowTwoFactorSecret() { ShowTwoFactorSecretViewModel model = null; using (var db = new MembershipContext()) { User user = db.Users.Single(u => u.UserId == WebSecurity.CurrentUserId); model = new ShowTwoFactorSecretViewModel() { UserName = user.UserName, EnableTwoFactorAuthentication = user.IsGoogleAuthenticatorEnabled, SecretKey = Base32.Base32Encoder.Encode(System.Text.Encoding.ASCII.GetBytes(user.TwoFactorSecret)) }; } return View(model); }