Browse Source

left-pad with zero in case code is less than 6 digits

master
Brad Parker 3 years ago
parent
commit
37e639480e
  1. 2
      mainwindow.cpp

2
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)");
}

Loading…
Cancel
Save