Skip to content

Commit edf9968

Browse files
authored
Merge pull request #161 from BrandonPotter/fix/30secondinterval
Fixed problem with 30 second interval
2 parents 7187f1f + ebecd17 commit edf9968

4 files changed

Lines changed: 34 additions & 3 deletions

File tree

Google.Authenticator.Tests/ValidationTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ public void ValidateWorksWithDifferentSecretTypes(string pin, int irrelevantNumb
3333
subject.ValidateTwoFactorPIN(secretAsBytes, pin, irrelevantNumberToAvoidDuplicatePinsBeingRemoved * 2);
3434
}
3535

36+
[Fact]
37+
public void GetCurrentPinsHandles15SecondInterval()
38+
{
39+
// This is nonsensical, really, as anything less than 30 == 0 in practice.
40+
var subject = new TwoFactorAuthenticator();
41+
42+
subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(15)).Length.ShouldBe(1);
43+
}
44+
45+
46+
[Fact]
47+
public void GetCurrentPinsHandles30SecondInterval()
48+
{
49+
var subject = new TwoFactorAuthenticator();
50+
51+
subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(30)).Length.ShouldBe(3);
52+
}
53+
54+
[Fact]
55+
public void GetCurrentPinsHandles60SecondInterval()
56+
{
57+
var subject = new TwoFactorAuthenticator();
58+
59+
subject.GetCurrentPINs(secret, TimeSpan.FromSeconds(60)).Length.ShouldBe(5);
60+
}
61+
3662
public static IEnumerable<object[]> GetPins()
3763
{
3864
var subject = new TwoFactorAuthenticator();

Google.Authenticator/Google.Authenticator.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
44
<Product>Google Authenticator Two-Factor</Product>
55
<Title>Google Authenticator Two-Factor Authentication Library</Title>
66
<Description>Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.)</Description>
77
<Authors>Brandon Potter</Authors>
88
<Company>Brandon Potter</Company>
9-
<Version>3.1.0</Version>
9+
<Version>3.1.1-beta1</Version>
1010
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
1111
<PackageProjectUrl>https://github.com/BrandonPotter/GoogleAuthenticator</PackageProjectUrl>
1212
<PackageId>GoogleAuthenticator</PackageId>

Google.Authenticator/TwoFactorAuthenticator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public string[] GetCurrentPINs(byte[] accountSecretKey, TimeSpan timeTolerance)
303303
{
304304
var iterationOffset = 0;
305305

306-
if (timeTolerance.TotalSeconds > 30)
306+
if (timeTolerance.TotalSeconds >= 30)
307307
iterationOffset = Convert.ToInt32(timeTolerance.TotalSeconds / 30.00);
308308

309309
return GetCurrentPINs(accountSecretKey, iterationOffset);

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ bool result = tfa.ValidateTwoFactorPIN(key, txtCode.Text)
3333

3434
## Update history
3535

36+
### 3.1.1-beta1
37+
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.
38+
39+
### 3.1.0
40+
3641
### 3.0.0
3742

3843
- Removed support for legacy .Net Framework. Lowest supported versions are now netstandard2.0 and .Net 4.6.2.

0 commit comments

Comments
 (0)