Skip to content

Commit

Permalink
Merge pull request #161 from BrandonPotter/fix/30secondinterval
Browse files Browse the repository at this point in the history
Fixed problem with 30 second interval
  • Loading branch information
ahwm authored May 30, 2023
2 parents 7187f1f + ebecd17 commit edf9968
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
26 changes: 26 additions & 0 deletions Google.Authenticator.Tests/ValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<object[]> GetPins()
{
var subject = new TwoFactorAuthenticator();
Expand Down
4 changes: 2 additions & 2 deletions Google.Authenticator/Google.Authenticator.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>
<Product>Google Authenticator Two-Factor</Product>
<Title>Google Authenticator Two-Factor Authentication Library</Title>
<Description>Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.)</Description>
<Authors>Brandon Potter</Authors>
<Company>Brandon Potter</Company>
<Version>3.1.0</Version>
<Version>3.1.1-beta1</Version>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/BrandonPotter/GoogleAuthenticator</PackageProjectUrl>
<PackageId>GoogleAuthenticator</PackageId>
Expand Down
2 changes: 1 addition & 1 deletion Google.Authenticator/TwoFactorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit edf9968

Please sign in to comment.