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:
parent
f432c2aa68
commit
287073afdc
4 changed files with 42 additions and 11 deletions
|
|
@ -52,6 +52,7 @@ public:
|
|||
*/
|
||||
bool initialized(QSqlDatabase &db);
|
||||
bool createDatabase(QSqlDatabase &db, QString passphrase);
|
||||
/// Opens the PSK database
|
||||
bool openDatabase(QSqlDatabase &db, QString passphrase);
|
||||
void closeDatabase();
|
||||
bool locked() const;
|
||||
|
|
|
|||
|
|
@ -188,16 +188,10 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
|
|||
bool ok = (exec_result == QDialog::Accepted);
|
||||
|
||||
// IF user gave OK
|
||||
if (ok) {
|
||||
if (m_passwordManager->openDatabase(m_userConfigDatabase, dlg->password())) {
|
||||
if (ok && m_passwordManager->openDatabase(m_userConfigDatabase, dlg->password()))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Ask user for passphrase + confirmation, clearly instruct this is first setup
|
||||
// create
|
||||
|
|
@ -209,11 +203,10 @@ bool MasterController::UnlockPasswordManagerIfNeeded()
|
|||
int exec_result = dlg->exec();
|
||||
if (exec_result == QDialog::Accepted) {
|
||||
QString passphrase = dlg->password();
|
||||
if (m_passwordManager->createDatabase(m_userConfigDatabase, passphrase)) {
|
||||
if (m_passwordManager->createDatabase(m_userConfigDatabase, passphrase))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "PasswordPromptDialog.h"
|
||||
#include <QtWidgets/QApplication>
|
||||
#include <QCheckBox>
|
||||
#include <QComboBox>
|
||||
#include <QDebug>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
|
|
@ -43,6 +45,21 @@ PasswordPromptDialog::PasswordPromptDialog(Flags flags, QWidget *parent)
|
|||
mainLayout->addWidget(m_saveCheck, row, 1);
|
||||
++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);
|
||||
setLayout(mainLayout);
|
||||
|
||||
|
|
@ -94,6 +111,8 @@ void PasswordPromptDialog::retranslateUi()
|
|||
m_passwordInput[1]->setPlaceholderText(QApplication::translate(translateContext, "Reenter same password for confirmation", nullptr));
|
||||
if (m_saveCheck)
|
||||
m_saveCheck->setText(QApplication::translate(translateContext, "Save password", nullptr));
|
||||
if (m_rememberLabel)
|
||||
m_rememberLabel->setText(QApplication::translate(translateContext, "Remember", nullptr));
|
||||
}
|
||||
|
||||
void PasswordPromptDialog::updateOkEnabled()
|
||||
|
|
@ -121,5 +140,15 @@ bool PasswordPromptDialog::saveChecked() const
|
|||
if (m_saveCheck)
|
||||
return m_saveCheck->checkState() == Qt::Checked;
|
||||
|
||||
qDebug() << "PasswordPromptDialog::saveChecked() called while SaveOption flag was not passed to constructor";
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <optional>
|
||||
|
||||
class QCheckBox;
|
||||
class QComboBox;
|
||||
class QDialogButtonBox;
|
||||
class QLabel;
|
||||
class QLineEdit;
|
||||
|
|
@ -15,7 +16,8 @@ class PasswordPromptDialog : public QDialog
|
|||
public:
|
||||
enum Flag {
|
||||
ConfirmPassword = 1,
|
||||
SaveOption = 2
|
||||
SaveOption = 2,
|
||||
RememberPassword = 4
|
||||
};
|
||||
|
||||
Q_DECLARE_FLAGS(Flags, Flag)
|
||||
|
|
@ -31,6 +33,10 @@ public:
|
|||
|
||||
QString password() 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:
|
||||
static const char* translateContext;
|
||||
|
||||
|
|
@ -39,6 +45,8 @@ private:
|
|||
QLabel *m_passwordLabel[2] = { nullptr, nullptr };
|
||||
QLineEdit *m_passwordInput[2] = { nullptr, nullptr };
|
||||
QCheckBox *m_saveCheck = nullptr;
|
||||
QLabel *m_rememberLabel = nullptr;
|
||||
QComboBox *m_rememberChoices = nullptr;
|
||||
QDialogButtonBox *m_DialogButtons = nullptr;
|
||||
|
||||
std::optional<QString> m_customCaption;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue