0

我在 ASP.NET 应用程序中使用GoogleAuthenticatornuget 包进行身份验证。问题是即使身份验证器应用程序已经更改了代码2FA,该函数也ValidateTwoFactorPIN总是返回。Nuget 包trueTOTP

TwoFactorSetupRequest 在控制台中打印

public TwoFactorSetupResponse Enable(string email)
        {
            var accountSecretKey = $"{SecretCode}-{email}";
            var setupInfo = _twoFactorAuthenticator.GenerateSetupCode("App", email, Encoding.ASCII.GetBytes(accountSecretKey));

            return new TwoFactorSetupResponse()
            {
                Account = setupInfo.Account,
                ManualEntryKey = setupInfo.ManualEntryKey,
                QrCodeSetupImageUrl = setupInfo.QrCodeSetupImageUrl,
            };
        }

        public bool IsCodeValid(string email, string code)
        {
            var accountSecretKey = $"{SecretCode}-{email}";
            return _twoFactorAuthenticator.ValidateTwoFactorPIN(accountSecretKey, code);
        }
4

1 回答 1

1

该软件包的默认漂移容差五分钟,因此要么使用较小的容差进行测试,要么等到容差窗口过去。

于 2021-12-16T00:26:41.057 回答