Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google authenticator with asp.net core

Are there any sample implementation for google authenticator as two factor authentication implementation in addition to sms and email?

Found one sample. Sample Google Authenticator using asp.net

But there are lots of changes while using it with asp.net core.

like image 734
Satyajit Avatar asked May 13 '17 17:05

Satyajit


1 Answers

You can use AspNetCore.Totp. https://github.com/damirkusar/AspNetCore.Totp

It works exactly like GoogleAuthenticator, have a look at the Tests project for the implementation (really simple).

You just have a couple of lines to write to get the qurcode and to validate the pin code:

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);
like image 175
Jean.R Avatar answered Sep 20 '22 04:09

Jean.R