-
Notifications
You must be signed in to change notification settings - Fork 128
Home
Aaron Hudon edited this page Apr 26, 2020
·
4 revisions
Welcome to the GoogleAuthenticator wiki!
Generate a new setup code. Ideally you will have some method of generating a random secret key, such as a password generation library.
using Google.Authenticator;
string key = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
SetupCode setupInfo = tfa.GenerateSetupCode("Test Two Factor", "[email protected]", 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);