Added remember option to password dialog.

Made to remember password of password manager for given time but not completely sure
how to implement that yet.
This commit is contained in:
eelke 2018-11-15 19:24:29 +01:00
parent f432c2aa68
commit 287073afdc
4 changed files with 42 additions and 11 deletions

View file

@ -52,6 +52,7 @@ public:
*/ */
bool initialized(QSqlDatabase &db); bool initialized(QSqlDatabase &db);
bool createDatabase(QSqlDatabase &db, QString passphrase); bool createDatabase(QSqlDatabase &db, QString passphrase);
/// Opens the PSK database
bool openDatabase(QSqlDatabase &db, QString passphrase); bool openDatabase(QSqlDatabase &db, QString passphrase);
void closeDatabase(); void closeDatabase();
bool locked() const; bool locked() const;

View file

@ -188,16 +188,10 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
bool ok = (exec_result == QDialog::Accepted); bool ok = (exec_result == QDialog::Accepted);
// IF user gave OK // IF user gave OK
if (ok) { if (ok && m_passwordManager->openDatabase(m_userConfigDatabase, dlg->password()))
if (m_passwordManager->openDatabase(m_userConfigDatabase, dlg->password())) {
return true; return true;
} }
} }
else {
return false;
}
}
}
else { else {
// Ask user for passphrase + confirmation, clearly instruct this is first setup // Ask user for passphrase + confirmation, clearly instruct this is first setup
// create // create
@ -209,11 +203,10 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
int exec_result = dlg->exec(); int exec_result = dlg->exec();
if (exec_result == QDialog::Accepted) { if (exec_result == QDialog::Accepted) {
QString passphrase = dlg->password(); QString passphrase = dlg->password();
if (m_passwordManager->createDatabase(m_userConfigDatabase, passphrase)) { if (m_passwordManager->createDatabase(m_userConfigDatabase, passphrase))
return true; return true;
} }
} }
}
return false; return false;
} }

View file

@ -1,6 +1,8 @@
#include "PasswordPromptDialog.h" #include "PasswordPromptDialog.h"
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
#include <QCheckBox> #include <QCheckBox>
#include <QComboBox>
#include <QDebug>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QLayout> #include <QLayout>
@ -43,6 +45,21 @@ PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
mainLayout->addWidget(m_saveCheck, row, 1); mainLayout->addWidget(m_saveCheck, row, 1);
++row; ++row;
} }
if (m_Flags.testFlag(RememberPassword)) {
m_rememberLabel = new QLabel(this);
mainLayout->addWidget(m_rememberLabel, row, 0);
m_rememberChoices = new QComboBox(this);
m_rememberChoices->addItem(tr("don't"), 0);
m_rememberChoices->addItem(tr("1 minute"), 1);
m_rememberChoices->addItem(tr("5 minutes"), 5);
m_rememberChoices->addItem(tr("15 minutes"), 15);
m_rememberChoices->addItem(tr("60 minutes"), 15);
m_rememberChoices->addItem(tr("until termination"), -1);
mainLayout->addWidget(m_rememberChoices, row, 1);
++row;
}
mainLayout->addWidget(m_DialogButtons, row, 0, 1 ,2); mainLayout->addWidget(m_DialogButtons, row, 0, 1 ,2);
setLayout(mainLayout); setLayout(mainLayout);
@ -94,6 +111,8 @@ void PasswordPromptDialog::retranslateUi()
m_passwordInput[1]->setPlaceholderText(QApplication::translate(translateContext, "Reenter same password for confirmation", nullptr)); m_passwordInput[1]->setPlaceholderText(QApplication::translate(translateContext, "Reenter same password for confirmation", nullptr));
if (m_saveCheck) if (m_saveCheck)
m_saveCheck->setText(QApplication::translate(translateContext, "Save password", nullptr)); m_saveCheck->setText(QApplication::translate(translateContext, "Save password", nullptr));
if (m_rememberLabel)
m_rememberLabel->setText(QApplication::translate(translateContext, "Remember", nullptr));
} }
void PasswordPromptDialog::updateOkEnabled() void PasswordPromptDialog::updateOkEnabled()
@ -121,5 +140,15 @@ bool PasswordPromptDialog::saveChecked() const
if (m_saveCheck) if (m_saveCheck)
return m_saveCheck->checkState() == Qt::Checked; return m_saveCheck->checkState() == Qt::Checked;
qDebug() << "PasswordPromptDialog::saveChecked() called while SaveOption flag was not passed to constructor";
return false; return false;
} }
int PasswordPromptDialog::remember() const
{
if (m_rememberChoices)
return m_rememberChoices->currentData().toInt();
qDebug() << "PasswordPromptDialog::remember() called while RememberPassword flag was not passed to constructor";
return 0;
}

View file

@ -5,6 +5,7 @@
#include <optional> #include <optional>
class QCheckBox; class QCheckBox;
class QComboBox;
class QDialogButtonBox; class QDialogButtonBox;
class QLabel; class QLabel;
class QLineEdit; class QLineEdit;
@ -15,7 +16,8 @@ class PasswordPromptDialog : public QDialog
public: public:
enum Flag { enum Flag {
ConfirmPassword = 1, ConfirmPassword = 1,
SaveOption = 2 SaveOption = 2,
RememberPassword = 4
}; };
Q_DECLARE_FLAGS(Flags, Flag) Q_DECLARE_FLAGS(Flags, Flag)
@ -31,6 +33,10 @@ public:
QString password() const; QString password() const;
bool saveChecked() const; bool saveChecked() const;
/// Returns how long the user wants the password remembered
///
/// \return time to remember password in minutes, 0= do not remember, -1= until termination
int remember() const;
private: private:
static const char* translateContext; static const char* translateContext;
@ -39,6 +45,8 @@ private:
QLabel *m_passwordLabel[2] = { nullptr, nullptr }; QLabel *m_passwordLabel[2] = { nullptr, nullptr };
QLineEdit *m_passwordInput[2] = { nullptr, nullptr }; QLineEdit *m_passwordInput[2] = { nullptr, nullptr };
QCheckBox *m_saveCheck = nullptr; QCheckBox *m_saveCheck = nullptr;
QLabel *m_rememberLabel = nullptr;
QComboBox *m_rememberChoices = nullptr;
QDialogButtonBox *m_DialogButtons = nullptr; QDialogButtonBox *m_DialogButtons = nullptr;
std::optional<QString> m_customCaption; std::optional<QString> m_customCaption;