From 37e639480e04469c125c2d7cc572314f3cf27bea Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Thu, 12 Aug 2021 18:30:26 -0400 Subject: [PATCH] left-pad with zero in case code is less than 6 digits --- mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 7a8e0ab..52fea4e 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -194,5 +194,5 @@ QString MainWindow::generateCode(QString key) { p = CppTotp::totp(qui, time(NULL), 0, 30, 6); // return only the first six digits, as a string, with a space in the middle - return QString::number(p).left(6).replace(QRegularExpression(R"((\d{3})(\d{3}))"), R"(\1 \2)"); + return QString::number(p).rightJustified(6, '0', true).replace(QRegularExpression(R"((\d{3})(\d{3}))"), R"(\1 \2)"); }