RobThree / TwoFactorAuth.Net

.Net library for Two Factor Authentication (TFA / 2FA)
MIT License
337 stars 59 forks source link

Not Working in Microsoft Authenticator App but in Google Authenticator #18

Open KBITSERVICES opened 3 years ago

KBITSERVICES commented 3 years ago

Hi,

i'm using the following code to generate QRCode for TOTP:

tfa = new TwoFactorAuth("ADRM", 6, 60);

secret = tfa.CreateSecret(80, CryptoSecureRequirement.RequireSecure);

secretlabel.Text = secret;

AppSettingsHandler.Handler.AddOrUpdateSetting("secret", secret);

String uri = tfa.GetQrText("ADRM", secret);

QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(uri, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

pictureBox1.Image = qrCodeImage;

My Problem is that if i scan the Code with Microsoft Authenticator i get an other code as Google Authenticator.

Googles Code is correct, microsoft's isnt.

Can you help please?

RobThree commented 3 years ago

Not all authenticators support all variations of periods, digits, algorithms and number of secret bits. So I'd start with testing the most common combination: 30 second periods, 6 digits, sha1, 80 bits. I see you're using 60 second periods so I bet that's the problem.

StuFrankish commented 2 years ago

Just to add to this as I've come across a similar issue. I've had to push the algorithm being used down to SHA1 for the most broad compatibility, as to date, the Microsoft authenticator app still won't work with SHA256 or SHA512.

Using a 6 digit code and 30s period.