Skip to content

Is this the way to add support for otp codes with leading zero correctly? #7

@Sailboat265

Description

@Sailboat265

Hi Jonathan Lusky, firstly, please let me say a big thank you for creating this HOTP library.

Alright, first things first.
I used a DS3231 RTC Module to generate the UNIX time needed for the counter.

Ultimately, the otp code generated by gen.generateHOTP() is correctly matched up with this totp generator website.

So, that mean this library is 100% compatible to be used as a TOTP generator.

The Problem
Because Arduino's Serial.print() function doesn't print leading zero. It will cause interesting problems.

For example, if the TOTP code now should be 000203. However, because of Serial.print()'s limitations, the otp code will look like 203 in the output, which is invalid.

Likely Solution
After countless hours of researching. Well, I think the likely solution is:

char buffer [64];
// Format the buffer?
sprintf(buffer, "Code is: %06lu", hotp);
// Then print it out
Serial.println(buffer);

The output will look like Code is: 000203.


I believe there are better solution that can fix the above problem ultimately and easily.
This solution now is like a "workaround" to me, it would be greatly appreciated if someone who has expertise in C++ can point out the better solution. Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions