diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2015-09-24 20:59:08 +0200 |
---|---|---|
committer | Anne Jan Brouwer <annejan@noprotocol.com> | 2015-09-24 20:59:08 +0200 |
commit | 92d7d009e8f6f7512f68136cf28d7253c7557853 (patch) | |
tree | 07e76a810b34b8ad544dd67d4a5ebed5dec71c69 /mainwindow.cpp | |
parent | d63b63fe3dc5cf748c2adad09b44b59ee52773d8 (diff) |
Safeguard agains modulus zero in password generator
Diffstat (limited to 'mainwindow.cpp')
-rw-r--r-- | mainwindow.cpp | 16 |
1 files changed, 11 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; |