codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.59k stars 1.09k forks source link

How do I get the code when using OneTimeCode provider #434

Closed koraybalci closed 1 year ago

koraybalci commented 1 year ago

Looking at the one-time-code example here, I am curious if I can retrieve somehow the x digit number generated, along with the image when I generate.

I am planning to display the 6 digit number (generated by the library) below the qr code image, is this possible?

codebude commented 1 year ago

The QRCoder doesn't generate the digits. You have to pass them in. If you pass them into the payload generator, you should have them already. ;-)

It's also described in the wiki:

The payload generator builds the correct payload for you, but it can't/doesn't calculate the TOTP/HOTP secret for you.

(https://github.com/codebude/QRCoder/wiki/Advanced-usage---Payload-generators#good-to-know-10)

TL;DR; Use a TOTP/HOTP library to generate the tokens and secrets and use the payload generator to format the output of your TOTP library in a way it can be encoded as QRCode.