I'm currently working on implementing OTP (One-Time Password) functionality in C# using the PureOtp library available on GitHub PureOtp. However, I'm facing an issue with the lifespan of the the codes seem to last only around 30 seconds. I'm looking for suggestions on how to increase this lifespan.
Here's the snippet of the code I'm using:generated OTP codes.
string? secret = "mysecretkey";var totp = new Totp(Encoding.UTF8.GetBytes(secret));RETRY:var otpCode = totp.ComputeTotp();Console.WriteLine(otpCode);var userInputOtp = Console.ReadLine();var isGood = totp.VerifyTotp(userInputOtp, out var timeStepMatched, VerificationWindow.RfcSpecifiedNetworkDelay);if (isGood){ Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Secret: " + secret +" Code: " + otpCode +" Result: passed"); Console.ResetColor();}else{ Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Secret: " + secret +" Code: " + otpCode +" Result: failed"); Console.ResetColor();}Console.WriteLine();Console.WriteLine("Press 'r' key to run again, press 'w' to wait 30 seconds for new code before running again");var cres = Console.ReadKey();Console.Write(new string('', Console.WindowWidth));Console.SetCursorPosition(0, Console.CursorTop - 2);Console.Write(new string('', Console.WindowWidth));Console.SetCursorPosition(0, Console.CursorTop);Console.Write(new string('', Console.WindowWidth));Console.SetCursorPosition(0, Console.CursorTop - 1);switch (cres.KeyChar){ case 'R': case 'r': Console.SetCursorPosition(0, Console.CursorTop - 1); Console.Write("RETRYING" + new string('', Console.WindowWidth - 8)); goto RETRY; case 'W': case 'w': Console.SetCursorPosition(0, Console.CursorTop - 1); Console.Write("RETRYING in 30 seconds" + new string('', Console.WindowWidth - 22)); Task.Delay(10000).Wait(); Console.Write("20 seconds"); Console.WriteLine(); Task.Delay(10000).Wait(); Console.Write("10 seconds"); Console.WriteLine(); Task.Delay(10000).Wait(); Console.Write("RETRYING" + new string('', Console.WindowWidth - 8)); Console.WriteLine(); goto RETRY;}
Any insights on how I can extend the validity period of these OTP codes beyond 30 seconds would be greatly appreciatedAdditionally, if you could provide more details on how the OTP code works internally or suggest alternative approaches for managing OTP lifespans effectively, it would be immensely helpful. Thank you!
I expecting to find a straightforward method within the PureOtp library to customize the lifespan of OTP codes