public async Task <ActionResult> EnableGoogleAuthenticator(GoogleAuthenticatorViewModel model)
        {
            if (ModelState.IsValid)
            {
                byte[] secretKey = Base32Encoder.Decode(model.SecretKey);

                long timeStepMatched = 0;
                var  otp             = new Totp(secretKey);
                if (otp.VerifyTotp(model.Code.Trim(), out timeStepMatched, new VerificationWindow(2, 2)))
                {
                    var user = UserManager.FindById(User.Identity.GetUserId());
                    user.IsGoogleAuthenticatorEnabled = true;
                    user.GoogleAuthenticatorSecretKey = model.SecretKey;
                    user.TwoFactorEnabled             = true;
                    await UserManager.UpdateAsync(user);

                    return(RedirectToAction("Index", "Manage"));
                }
                else
                {
                    ModelState.AddModelError("Code", "Code không đúng");
                }
            }

            return(View(model));
        }
        public ActionResult EnableGoogleAuthenticator()
        {
            byte[] secretKey     = KeyGeneration.GenerateRandomKey(20);
            string userName      = User.Identity.GetUserName();
            string issuer        = "CMS Xây dựng Minh Thanh";
            string issuerEncoded = HttpUtility.UrlEncode(issuer);
            string barcodeUrl    = KeyUrl.GetTotpUrl(secretKey, userName) + "&issuer=" + issuerEncoded;

            var model = new GoogleAuthenticatorViewModel
            {
                SecretKey  = Base32Encoder.Encode(secretKey),
                BarcodeUrl = barcodeUrl
            };

            return(View(model));
        }