【问题标题】:Google Authenticator 2FA returning True alwaysGoogle Authenticator 2FA 总是返回 True
【发布时间】:2022-01-19 02:54:59
【问题描述】:

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

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);
        }

【问题讨论】:

    标签: asp.net .net .net-core google-2fa


    【解决方案1】:

    那个包的默认drift tolerancefive minutes,所以要么用较小的容差进行测试,要么等到容差窗口过去。

    【讨论】:

    • 你知道我可以如何更改电子规范吗?
    • 使用允许指定您自己的容差的重载github.com/BrandonPotter/GoogleAuthenticator/blob/…
    • 现在它返回 false。也许我做的不对,你知道我在哪里可以看到一个例子吗?
    • False 带什么参数?您的服务器和您的设备可能存在时差。
    • 一段时间后就可以使用了,谢谢!
    猜你喜欢
    • 2013-08-06
    • 2017-05-10
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多