diff --git a/Google.Authenticator.Tests/ValidationTests.cs b/Google.Authenticator.Tests/ValidationTests.cs index 64c232e..d80a2e4 100644 --- a/Google.Authenticator.Tests/ValidationTests.cs +++ b/Google.Authenticator.Tests/ValidationTests.cs @@ -33,6 +33,32 @@ public void ValidateWorksWithDifferentSecretTypes(string pin, int irrelevantNumb subject.ValidateTwoFactorPIN(secretAsBytes, pin, irrelevantNumberToAvoidDuplicatePinsBeingRemoved * 2); } + [Fact] + public void GetCurrentPinsHandles15SecondInterval() + { + // This is nonsensical, really, as anything less than 30 == 0 in practice. + var subject = new TwoFactorAuthenticator(); + + subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(15)).Length.ShouldBe(1); + } + + + [Fact] + public void GetCurrentPinsHandles30SecondInterval() + { + var subject = new TwoFactorAuthenticator(); + + subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(30)).Length.ShouldBe(3); + } + + [Fact] + public void GetCurrentPinsHandles60SecondInterval() + { + var subject = new TwoFactorAuthenticator(); + + subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(60)).Length.ShouldBe(5); + } + public static IEnumerable GetPins() { var subject = new TwoFactorAuthenticator(); diff --git a/Google.Authenticator/Google.Authenticator.csproj b/Google.Authenticator/Google.Authenticator.csproj index 5092736..6d0f47e 100644 --- a/Google.Authenticator/Google.Authenticator.csproj +++ b/Google.Authenticator/Google.Authenticator.csproj @@ -1,4 +1,4 @@ - + netstandard2.0;net462 Google Authenticator Two-Factor @@ -6,7 +6,7 @@ Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.) Brandon Potter Brandon Potter - 3.1.0 + 3.1.1-beta1 Apache-2.0 https://github.com/BrandonPotter/GoogleAuthenticator GoogleAuthenticator diff --git a/Google.Authenticator/TwoFactorAuthenticator.cs b/Google.Authenticator/TwoFactorAuthenticator.cs index 505560f..2904f56 100644 --- a/Google.Authenticator/TwoFactorAuthenticator.cs +++ b/Google.Authenticator/TwoFactorAuthenticator.cs @@ -303,7 +303,7 @@ public string[] GetCurrentPINs(byte[] accountSecretKey, TimeSpan timeTolerance) { var iterationOffset = 0; - if (timeTolerance.TotalSeconds > 30) + if (timeTolerance.TotalSeconds >= 30) iterationOffset = Convert.ToInt32(timeTolerance.TotalSeconds / 30.00); return GetCurrentPINs(accountSecretKey, iterationOffset); diff --git a/README.md b/README.md index 14186c0..1c907cb 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,11 @@ bool result = tfa.ValidateTwoFactorPIN(key, txtCode.Text) ## Update history +### 3.1.1-beta1 +Fixed an edge case where specifying an interval of 30 seconds to the Validate function would be treated as if you had passed in 0. + +### 3.1.0 + ### 3.0.0 - Removed support for legacy .Net Framework. Lowest supported versions are now netstandard2.0 and .Net 4.6.2.