Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jul 7, 2021

Fix for issue # 65;
Support for .net5;
Small refactoring.

…the secretKey parameter is base32 encoded string - fixed

Fix for issue # 65;
Support for .net5;
Small refactoring.
@ahwm ahwm requested a review from flytzen July 7, 2021 21:42
…f the secretKey parameter is base32 encoded string

Added parameter secretIsBase32 into ValidateTwoFactorPIN
Copy link
Collaborator

@flytzen flytzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this and for fixing the issue.
I would prefer to leave {} around the body of if/else; it is more verbose but is recommended practice because it prevents subtle errors.
If at all possible, could you add a unit test that would have failed before the fix and passes after? Reason is, the code looks good, but I don't actually know if it works and a unit test would show that.

Thank you again, great work!

{
throw new ArgumentNullException("input");
}
throw new ArgumentNullException(nameof(input));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

//if we didn't end with a full byte
if (arrayIndex != byteCount)
{
returnArray[arrayIndex] = curByte;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

{
throw new ArgumentNullException("input");
}
throw new ArgumentNullException(nameof(input));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

var value = (int)c;

//65-90 == uppercase letters
if (value < 91 && value > 64)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

//50-55 == numbers 2-7
if (value < 56 && value > 49)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

}
else
{
// https://github.com/google/google-authenticator/wiki/Conflicting-Accounts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove these comments

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that was not on purpose. Returned it.

{
result.Append(symbol);
}
if (validChars.IndexOf(symbol) == -1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

{
result.Append('%' + String.Format("{0:X2}", (int)symbol));
}
result.Append(symbol);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't remove {} here

bool secretIsBase32,
int digits = 6)
=> GenerateHashedCode(
secretIsBase32 ? Base32Encoding.ToBytes(secret):Encoding.UTF8.GetBytes(secret),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

string twoFactorCodeFromClient,
TimeSpan timeTolerance,
bool secretIsBase32 = false) =>
GetCurrentPINs(accountSecretKey, timeTolerance, secretIsBase32).Any(c => c == twoFactorCodeFromClient);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is more compact, but I think it hurts legibility. I am not too bothered, but I prefer the previous form here.

…the secretKey parameter is base32 encoded string - fixes for review

actual.ShouldBe(expected);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

@flytzen
Copy link
Collaborator

flytzen commented Jul 8, 2021

@ahwm LGTM, you happy to merge?
Given that we are changing the public interface, we should probably increment the major version?
And then we need to raise @BrandonPotter to get a deploy running :)

@ghost
Copy link
Author

ghost commented Jul 8, 2021

@ahwm LGTM, you happy to merge?
Given that we are changing the public interface, we should probably increment the major version?
And then we need to raise @BrandonPotter to get a deploy running :)

It will be great if the Nuget package is upgraded! Then I will be able to use it in our product ;) Thank you in advance!

@BrandonPotter
Copy link
Owner

Good stuff here!

@ahwm
Copy link
Collaborator

ahwm commented Jul 8, 2021

@ahwm LGTM, you happy to merge?
Given that we are changing the public interface, we should probably increment the major version?
And then we need to raise @BrandonPotter to get a deploy running :)

I'm happy to merge. Yes the public API is being changed, but it's been done in a backwards-compatible way (parameters with a default value last in the list) so it's not going to break existing integrations that update to it. So I think we can get by with a minor version increment.

So instead of 2.1.2 it would be 2.2.0.

@flytzen @BrandonPotter if you're both good with that version number then I'll make the version edit and merge.

@flytzen
Copy link
Collaborator

flytzen commented Jul 9, 2021

@ahwm agreed, thank you 💯

@BrandonPotter
Copy link
Owner

Agreed!

@ghost
Copy link
Author

ghost commented Jul 12, 2021

@awhm could you please update the Nuget package to include these changes? Thank you very much in advance.

@ahwm
Copy link
Collaborator

ahwm commented Jul 12, 2021

@caterina-novak pending #67

@ahwm
Copy link
Collaborator

ahwm commented Jul 13, 2021

@caterina-novak NuGet is pushed and should be live in a short period.

@ghost
Copy link
Author

ghost commented Jul 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants