Google аутентификатор с ядром asp.net
Есть ли пример реализации google authenticator в качестве двухфакторной реализации аутентификации в дополнение к смс и электронной почте?
Нашел один образец. Пример Google Authenticator с использованием asp.net
Но есть много изменений при использовании его с ядром asp.net.
1 ответ
Вы можете использовать AspNetCore.Totp. https://github.com/damirkusar/AspNetCore.Totp
Он работает точно так же, как GoogleAuthenticator, взгляните на проект Tests для реализации (очень просто).
Вам просто нужно написать пару строк, чтобы получить qurcode и проверить пин-код:
using AspNetCore.Totp;
...
// To generate the qrcode/setup key
var totpSetupGenerator = new TotpSetupGenerator();
var totpSetup = totpSetupGenerator.Generate("You app name here", "The username", "YourSuperSecretKeyHere", 300, 300);
string qrCodeImageUrl = totpSetup.QrCodeImage;
string manualEntrySetupCode = totpSetup.ManualSetupKey;
// To validate the pin after user input (where pin is an int variable)
var totpValidator = new TotpValidator();
bool isCorrectPIN = totpValidator.Validate("YourSuperSecretKeyHere", pin);