Fork of Google Authenticator Two-Factor Authentication Library (Not officially affiliated with Google.) This branch supposrts using different qrcode generators. You must either include a reference to QRCoder or SkiaSharp.QrCode in order to generate a qrcode image.
$ dotnet add package GoogleAuthenticator.MutlipleQRCoderSimple, easy to use server-side two-factor authentication library for .NET that works with Google Authenticator
Install-Package GoogleAuthenticator
See blog post for usage instructions (1.x only):
Additional examples at Google.Authenticator.WinTest and Google.Authenticator.WebSample
using Google.Authenticator;
string key = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
SetupCode setupInfo = tfa.GenerateSetupCode("Test Two Factor", "user@example.com", key, false, 3);
string qrCodeImageUrl = setupInfo.QrCodeSetupImageUrl;
string manualEntrySetupCode = setupInfo.ManualEntryKey;
imgQrCode.ImageUrl = qrCodeImageUrl;
lblManualSetupCode.Text = manualEntrySetupCode;
// verify
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
bool result = tfa.ValidateTwoFactorPIN(key, txtCode.Text)
Now runs on .Net 6.0.
Technically the QR Coder library we rely on still does not fully support .Net 6.0 so it is possible there will be other niggling issues, but for now all tests pass for .Net 6.0 on both Windows and Linux.
ManualEntryKey interchangeably. ManualEntryKey is used to enter into the authenticator app when scanning a QR code is impossible and is derived from the secret key (discussion example)On linux, you need to ensure libgdiplus is installed if you want to generate QR Codes. See https://github.com/codebude/QRCoder/issues/227.