Skip to content

Commit ec02de0

Browse files
authored
Merge pull request #276 from treat1/master
small band aid fix for password generation on windows
2 parents 0d43006 + e20a909 commit ec02de0

File tree

6 files changed

+20
-3
lines changed

6 files changed

+20
-3
lines changed

.appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
install:
22
- set QTDIR=C:\Qt\5.7\mingw53_32
33
- choco install -y InnoSetup
4-
- set PATH=%QTDIR%\bin;C:\MinGW\bin;%PATH%;"C:\Program Files (x86)\Inno Setup 5"
4+
- set PATH=%QTDIR%\bin;C:\Qt\Tools\mingw530_32\bin;%PATH%;"C:\Program Files (x86)\Inno Setup 5"
55
build_script:
66
- qmake qtpass.pro CONFIG+=static
77
- mingw32-make

src/pass.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ QString Pass::Generate_b(int length, const QString &charset) {
9191
} else {
9292
if (charset.length() > 0) {
9393
for (int i = 0; i < length; ++i) {
94-
int index = qrand() % charset.length();
94+
int index = Util::rand() % charset.length();
9595
QChar nextChar = charset.at(index);
9696
passwd.append(nextChar);
9797
}

src/src.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ win32 {
164164
}
165165
gcc:QMAKE_LFLAGS += -Wl,--dynamicbase -Wl,--nxcompat
166166
msvc:QMAKE_LFLAGS += /DYNAMICBASE /NXCOMPAT
167-
LIBS += -lmpr
167+
LIBS += -lmpr -lbcrypt
168168
} else:macx {
169169
ICON = ../artwork/icon.icns
170170
QMAKE_INFO_PLIST = ../qtpass.plist

src/util.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <QString>
77
#ifdef Q_OS_WIN
88
#include <windows.h>
9+
#include <bcrypt.h>
910
#else
1011
#include <sys/time.h>
1112
#endif
@@ -176,3 +177,14 @@ void Util::copyDir(const QString src, const QString dest) {
176177
dest + QDir::separator() + file);
177178
}
178179
}
180+
181+
int Util::rand() {
182+
#ifdef Q_OS_WIN
183+
quint32 ret = 0;
184+
if (FAILED(BCryptGenRandom(NULL, (PUCHAR)&ret, sizeof(ret), BCRYPT_USE_SYSTEM_PREFERRED_RNG)))
185+
return qrand();
186+
return ret%RAND_MAX;
187+
#else
188+
return qrand();
189+
#endif
190+
}

src/util.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class Util {
2222
const QFileSystemModel &model,
2323
const StoreModel &storeModel);
2424
static void copyDir(const QString src, const QString dest);
25+
static int rand();
2526

2627
private:
2728
static void initialiseEnvironment();

tests/auto/util/util.pro

+4
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ HEADERS += util.h \
2121

2222
VPATH += ../../../src
2323
INCLUDEPATH += ../../../src
24+
25+
win32 {
26+
LIBS += -lbcrypt
27+
}

0 commit comments

Comments
 (0)