title: Two factor authentication invalid Code always
body: <p>i have set up the 2fa but always it says invalid code.</p>
  
  <p>i have tried it with the .net core 2.1 and 2.2. but always it says invalid code from the google as well as Microsoft authenticator.</p>
  
  <p>//Enable Authenticator.cshtml</p>
  
  <pre><code>&lt;p&gt;Scan the QR Code or enter this key &lt;kbd&gt;@Model.SharedKey&lt;/kbd&gt; 
  into your two factor authenticator app. Spaces and casing do not matter. 
  &lt;/p&gt;
  &lt;div class="alert alert-info"&gt;To enable QR code generation please 
  read our &lt;a href="https://go.microsoft.com/fwlink/? 
  Linkid=852423"&gt;documentation&lt;/a&gt;.&lt;/div&gt;
  &lt;div id="qrCode"&gt;&lt;/div&gt;
  &lt;div id="qrCodeData" data- 
  url="@Html.Raw(@Model.AuthenticatorUri)"&gt;&lt;/div&gt;
  //Js in Enable Authenticator.cshtml
  @section Scripts {
  &lt;partial name="_ValidationScriptsPartial" /&gt;
  &lt;script type="text/javascript" src="~/lib/qrcode.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  new QRCode(document.getElementById("qrCode"),
  {
  text: "@Html.Raw(Model.AuthenticatorUri)",
  width: 200,
  height: 200
  });
  &lt;/script&gt;
  //Enable Authenticator.cshtml.cs
  var user = await _userManager.GetUserAsync(User);
          if (user == null)
          {
              return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
          }
  
          if (!ModelState.IsValid)
          {
              await LoadSharedKeyAndQrCodeUriAsync(user);
              return Page();
          }
  
          // Strip spaces and hypens
          var verificationCode = Input.Code.Replace(" ", string.Empty).Replace("-", string.Empty);
  
          var is2faTokenValid = await _userManager.VerifyTwoFactorTokenAsync(
              user, _userManager.Options.Tokens.AuthenticatorTokenProvider, verificationCode);
  
          if (!is2faTokenValid)
          {
              ModelState.AddModelError("Input.Code", "Verification code is invalid.");
              await LoadSharedKeyAndQrCodeUriAsync(user);
              return Page();
          }
  
          await _userManager.SetTwoFactorEnabledAsync(user, true);
          var userId = await _userManager.GetUserIdAsync(user);
          _logger.LogInformation("User with ID '{UserId}' has enabled 2FA with an authenticator app.", userId);
  
          StatusMessage = "Your authenticator app has been verified.";
  
          if (await _userManager.CountRecoveryCodesAsync(user) == 0)
          {
              var recoveryCodes = await _userManager.GenerateNewTwoFactorRecoveryCodesAsync(user, 10);
              RecoveryCodes = recoveryCodes.ToArray();
              return RedirectToPage("./ShowRecoveryCodes");
          }
          else
          {
              return RedirectToPage("./TwoFactorAuthentication");
          }
  </code></pre>
  
  <p>i want to setup the authentication but its always invalid code.</p>