Skip to content

Commit

Permalink
qt: askpassphrasedialog: Clear pass fields on accept
Browse files Browse the repository at this point in the history
This is usability improvement in a case if user gets re-asked
passphrase. (e.g. made a typo)
  • Loading branch information
recursive-rat4 committed May 19, 2016
1 parent 7771aa5 commit 02ce2a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/qt/askpassphrasedialog.cpp
Expand Up @@ -77,10 +77,7 @@ AskPassphraseDialog::AskPassphraseDialog(Mode mode, QWidget *parent) :

AskPassphraseDialog::~AskPassphraseDialog()
{
// Attempt to overwrite text so that they do not linger around in memory
ui->passEdit1->setText(QString(" ").repeated(ui->passEdit1->text().size()));
ui->passEdit2->setText(QString(" ").repeated(ui->passEdit2->text().size()));
ui->passEdit3->setText(QString(" ").repeated(ui->passEdit3->text().size()));
secureClearPassFields();
delete ui;
}

Expand All @@ -103,6 +100,8 @@ void AskPassphraseDialog::accept()
newpass1.assign(ui->passEdit2->text().toStdString().c_str());
newpass2.assign(ui->passEdit3->text().toStdString().c_str());

secureClearPassFields();

switch(mode)
{
case Encrypt: {
Expand Down Expand Up @@ -260,3 +259,17 @@ bool AskPassphraseDialog::eventFilter(QObject *object, QEvent *event)
}
return QDialog::eventFilter(object, event);
}

static void SecureClearQLineEdit(QLineEdit* edit)
{
// Attempt to overwrite text so that they do not linger around in memory
edit->setText(QString(" ").repeated(edit->text().size()));
edit->clear();
}

void AskPassphraseDialog::secureClearPassFields()
{
SecureClearQLineEdit(ui->passEdit1);
SecureClearQLineEdit(ui->passEdit2);
SecureClearQLineEdit(ui->passEdit3);
}
1 change: 1 addition & 0 deletions src/qt/askpassphrasedialog.h
Expand Up @@ -42,6 +42,7 @@ class AskPassphraseDialog : public QDialog

private Q_SLOTS:
void textChanged();
void secureClearPassFields();

protected:
bool event(QEvent *event);
Expand Down

0 comments on commit 02ce2a3

Please sign in to comment.