Skip to content

Commit

Permalink
Safeguard agains modulus zero in password generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Anne Jan Brouwer committed Sep 24, 2015
1 parent 5df5ca1 commit 7e735f3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions qtpass.pro
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

macx {
TARGET = QtPass
QMAKE_MAC_SDK = macosx10.11
} else {
TARGET = qtpass
}
Expand Down

0 comments on commit 7e735f3

Please sign in to comment.