Skip to content

Commit

Permalink
Use length of existing password for the password generator (#2318)
Browse files Browse the repository at this point in the history
Add optional length parameter to PasswordGeneratorWidget::reset()
(default=0), which when >0 sets the legth SpinBox's value to the value
passed in. The EditEntryWidget already called reset() when the password
was known, so the current length was just added to this call (accounts
for empty passwords)

If entry edit is cancelled, return the password generator length to the
application default or last committed length if available. This is done
by calling reseting the password generator in EditEntryWidget::cancel()
when the edit page is being closed

Fixes #2180
  • Loading branch information
kneitinger authored and droidmonkey committed Sep 26, 2018
1 parent e7c5e17 commit d4112fe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/gui/PasswordGeneratorWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,15 @@ void PasswordGeneratorWidget::saveSettings()
config()->set("generator/Type", m_ui->tabWidget->currentIndex());
}

void PasswordGeneratorWidget::reset()
void PasswordGeneratorWidget::reset(int length)
{
m_ui->editNewPassword->setText("");
if (length > 0) {
m_ui->spinBoxLength->setValue(length);
} else {
m_ui->spinBoxLength->setValue(config()->get("generator/Length", PasswordGenerator::DefaultLength).toInt());
}

setStandaloneMode(false);
setPasswordVisible(config()->get("security/passwordscleartext").toBool());
updateGenerator();
Expand Down
2 changes: 1 addition & 1 deletion src/gui/PasswordGeneratorWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PasswordGeneratorWidget : public QWidget
~PasswordGeneratorWidget();
void loadSettings();
void saveSettings();
void reset();
void reset(int length = 0);
void setStandaloneMode(bool standalone);
QString getGeneratedPassword();
bool isPasswordVisible() const;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/entry/EditEntryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
m_mainUi->notesHint->setVisible(config()->get("security/hidenotes").toBool());
m_mainUi->togglePasswordGeneratorButton->setChecked(false);
m_mainUi->togglePasswordGeneratorButton->setDisabled(m_history);
m_mainUi->passwordGenerator->reset();
m_mainUi->passwordGenerator->reset(entry->password().length());

m_advancedUi->attachmentsWidget->setReadOnly(m_history);
m_advancedUi->addAttributeButton->setEnabled(!m_history);
Expand Down Expand Up @@ -934,6 +934,7 @@ void EditEntryWidget::cancel()
QMessageBox::Cancel | QMessageBox::Save | QMessageBox::Discard,
QMessageBox::Cancel);
if (result == QMessageBox::Cancel) {
m_mainUi->passwordGenerator->reset();
return;
}
if (result == QMessageBox::Save) {
Expand Down

0 comments on commit d4112fe

Please sign in to comment.