diff --git a/src/pass.cpp b/src/pass.cpp index a755a2ae9..242711fc1 100644 --- a/src/pass.cpp +++ b/src/pass.cpp @@ -91,7 +91,7 @@ QString Pass::Generate_b(int length, const QString &charset) { } else { if (charset.length() > 0) { for (int i = 0; i < length; ++i) { - int index = qrand() % charset.length(); + int index = Util::rand() % charset.length(); QChar nextChar = charset.at(index); passwd.append(nextChar); } diff --git a/src/src.pro b/src/src.pro index 0a5811a58..d2eada8b8 100644 --- a/src/src.pro +++ b/src/src.pro @@ -164,7 +164,7 @@ win32 { } gcc:QMAKE_LFLAGS += -Wl,--dynamicbase -Wl,--nxcompat msvc:QMAKE_LFLAGS += /DYNAMICBASE /NXCOMPAT - LIBS += -lmpr + LIBS += -lmpr -lbcrypt } else:macx { ICON = ../artwork/icon.icns QMAKE_INFO_PLIST = ../qtpass.plist diff --git a/src/util.cpp b/src/util.cpp index a242c554c..696d97a31 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -6,6 +6,7 @@ #include #ifdef Q_OS_WIN #include +#include #else #include #endif @@ -176,3 +177,13 @@ void Util::copyDir(const QString src, const QString dest) { dest + QDir::separator() + file); } } + +int Util::rand() { +#ifdef Q_OS_WIN + quint32 ret; + BCryptGenRandom(NULL, (PUCHAR)&ret, sizeof(ret), BCRYPT_USE_SYSTEM_PREFERRED_RNG); + return ret%RAND_MAX; +#else + return qrand(); +#endif +} diff --git a/src/util.h b/src/util.h index b980edf8a..c57c360ef 100644 --- a/src/util.h +++ b/src/util.h @@ -21,7 +21,8 @@ class Util { static QString getDir(const QModelIndex &index, bool forPass, const QFileSystemModel &model, const StoreModel &storeModel); - static void copyDir(const QString src, const QString dest); + static void copyDir(const QString src, const QString dest);\ + static int rand(); private: static void initialiseEnvironment(); diff --git a/tests/auto/util/util.pro b/tests/auto/util/util.pro index 0492abedb..1c8ba7cf9 100644 --- a/tests/auto/util/util.pro +++ b/tests/auto/util/util.pro @@ -21,3 +21,7 @@ HEADERS += util.h \ VPATH += ../../../src INCLUDEPATH += ../../../src + +win32 { + LIBS += -lbcrypt +}