diff options
Diffstat (limited to 'src/main/oshelper.cpp')
| -rw-r--r-- | src/main/oshelper.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index d44fc8c2..2ca0e400 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -43,6 +43,8 @@ #include <QFileInfo> #include <QString> #include <QUrl> +#include <QByteArray> +#include <QRandomGenerator> #ifdef Q_OS_MAC #include "qt/macoshelper.h" #endif @@ -246,6 +248,18 @@ QString OSHelper::temporaryPath() const return QDir::tempPath(); } +QString OSHelper::randomPassword(int numBytes) const +{ + numBytes = qBound(16, numBytes, 128); + + QByteArray buf(numBytes, Qt::Uninitialized); + auto *rng = QRandomGenerator::system(); + for (int i = 0; i < numBytes; ++i) + buf[i] = char(rng->generate() & 0xFF); + + return QString::fromLatin1(buf.toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals)); +} + bool OSHelper::installed() const { #ifdef Q_OS_WIN |
