Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed problem with 30 second interval #161

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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