TOTP and HOTP two-factor authentication library for .NET Standard 2.0, .NET 4.72, .NET 4.8, and .NET 8.0. Includes QR code generation and validation.
$ dotnet add package CGLibs.2FAOTP, HOTP and TOTP library for .NET. Create and validate 6-8 digit codes.
CGLibs._2FA.Imaging.Authenticator auth = new CGLibs._2FA.Imaging.Authenticator();
auth.Width = 500;
auth.Height = 500;
auth.Period = 60;
pictureBox1.Image = auth.GetQRCodeImage("$ecretKeyForTestingPurposesThatIsReallyLongAndCrazyToTryAndUse",
"Issuer", "UserAccount@SomeDomainOrAppEtc");
TOTPGenerator totpGenerator = new CGLibs._2FA.TOTP.TOTPGenerator("SecretKey");
string code = totpGenerator.GenerateForDate();
string usercode = "123456";
TOTPValidator totpValidator = new CGLibs._2FA.TOTP.TOTPValidator("SecretKey");
bool isValid = totpGenerator.Validate(usercode);
Thanks to ZXing.Net for QR code generation!
https://github.com/micjahn/ZXing.Net