summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnne Jan Brouwer <annejan@noprotocol.com>2015-09-24 20:59:08 +0200
committerAnne Jan Brouwer <annejan@noprotocol.com>2015-09-24 20:59:08 +0200
commit7e735f372becc03112bc6d4b89d93dd00c786f9f (patch)
tree07e76a810b34b8ad544dd67d4a5ebed5dec71c69
parent5df5ca180f2ca9940a43b3b7c6f47f2a9fd0295a (diff)
Safeguard agains modulus zero in password generator
-rw-r--r--mainwindow.cpp16
-rw-r--r--qtpass.pro1
2 files changed, 12 insertions, 5 deletions
diff --git a/mainwindow.cpp b/mainwindow.cpp
index ce7ce719..be9a873e 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1637,11 +1637,17 @@ QString MainWindow::generatePassword() {
qDebug() << "pwgen fail";
}
} else {
- for(int i=0; i<passwordLength; ++i)
- {
- int index = qrand() % passwordChars.length();
- QChar nextChar = passwordChars.at(index);
- passwd.append(nextChar);
+ int length = passwordChars.length();
+ if (length > 0) {
+ for(int i=0; i<passwordLength; ++i)
+ {
+ int index = qrand() % length;
+ QChar nextChar = passwordChars.at(index);
+ passwd.append(nextChar);
+ }
+ } else {
+ QMessageBox::critical(this, tr("No characters chosen"),
+ tr("Can't generate password, there are no characters to choose from set in the configuration!"));
}
}
return passwd;
diff --git a/qtpass.pro b/qtpass.pro
index d2098fd2..662e824c 100644
--- a/qtpass.pro
+++ b/qtpass.pro
@@ -13,6 +13,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
macx {
TARGET = QtPass
+ QMAKE_MAC_SDK = macosx10.11
} else {
TARGET = qtpass
}