Skip to content

Commit

Permalink
Issue BrandonPotter#65 - ValidateTwoFactorPin always returns false, i…
Browse files Browse the repository at this point in the history
…f the secretKey parameter is base32 encoded string

Added parameter secretIsBase32 into ValidateTwoFactorPIN
  • Loading branch information
kateryna-novak committed Jul 7, 2021
1 parent b5ea257 commit ff44a79
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Google.Authenticator/TwoFactorAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,18 @@ private string GenerateHashedCode(byte[] key, long iterationNumber, int digits =
private long GetCurrentCounter(DateTime now, DateTime epoch, int timeStep) =>
(long) (now - epoch).TotalSeconds / timeStep;

public bool ValidateTwoFactorPIN(string accountSecretKey, string twoFactorCodeFromClient) =>
ValidateTwoFactorPIN(accountSecretKey, twoFactorCodeFromClient, DefaultClockDriftTolerance);
public bool ValidateTwoFactorPIN(
string accountSecretKey,
string twoFactorCodeFromClient,
bool secretIsBase32 = false) =>
ValidateTwoFactorPIN(accountSecretKey, twoFactorCodeFromClient, DefaultClockDriftTolerance, secretIsBase32);

public bool ValidateTwoFactorPIN(
string accountSecretKey,
string twoFactorCodeFromClient,
TimeSpan timeTolerance)
=> GetCurrentPINs(accountSecretKey, timeTolerance).Any(c => c == twoFactorCodeFromClient);
TimeSpan timeTolerance,
bool secretIsBase32 = false) =>
GetCurrentPINs(accountSecretKey, timeTolerance, secretIsBase32).Any(c => c == twoFactorCodeFromClient);

public string GetCurrentPIN(string accountSecretKey, bool secretIsBase32 = false) =>
GeneratePINAtInterval(accountSecretKey, GetCurrentCounter(), secretIsBase32: secretIsBase32);
Expand Down

0 comments on commit ff44a79

Please sign in to comment.