Yortw / Yort.Otp

A portable .Net class library for creating onetime passwords (based on rfc4226 - https://tools.ietf.org/html/rfc4226 and rfc6238 - https://tools.ietf.org/html/rfc6238)
http://yortw.github.io/Yort.Otp/
MIT License
18 stars 1 forks source link

Time based factory generator doesn't have ValidUntilUtc property #3

Closed ruisilva450 closed 6 years ago

ruisilva450 commented 6 years ago

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 6 years ago

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()}");