Yortw/Yort.Otp

Time based factory generator doesn't have ValidUntilUtc property

Closed this issue · 1 comments

Hi,
When using the code from you sample about the Time Based Factory, you are getting ValidUntilUtc property from the generator object. I can't find this property when trying to do the same.

// Time based factory sample
//During startup, obtain and keep a reference to a factory
_OtpFactory = OnetimePasswordGeneratorFactory.CreateFactory(true, new Sha512HashAlgorithm(), 8, TimeSpan.FromMinutes(1));

//When you want to generate a password...
using (var passwordGenerator = _OtpFactory.CreateNewPasswordGenerator(OnetimePasswordSecret.FromAscii("12345678901234567890")))
{
	System.Diagnostics.Debug.WriteLine($"Password: {passwordGenerator.GeneratedPassword} valid until {passwordGenerator.ValidUntilUtc.ToLocalTime()}");
}
Yortw commented

Apologies for the error in the sample. The property is available, but only as part of the TimeBasedPasswordGenerator type as it does not apply to CounterBasedPasswordGenerator. The sample can be fixed by casting the generator obtained from the factory to TimeBasedPasswordGenerator.

    System.Diagnostics.Debug.WriteLine($"Password: {passwordGenerator.GeneratedPassword} valid until {((TimeBasedPasswordGenerator)passwordGenerator).ValidUntilUtc.ToLocalTime()}");