servatrice/cockatrice/src/dlg_edit_password.cpp
ebbit1q 2fc85e0c08
use hashed passwords in all commands (#4493)
* protocol changes

* server changes

* client changes for password reset and registration

* add hashed password to change password in client

* always use hashed password to log in

* add warning to client when using plain text password

* require real password for changing email on server

this is backwards compatible as users logged in with a real password on
older clients will not need this, only users logged in with a hashed
password

* implement password dialog when changing email

* require min password length

* use qstringlist to build query instead

* use clear instead of = ""

* add max to password dialog

* use proper const ness in abstractclient

* reject too long passwords instead of trimming
2022-01-16 20:32:30 -05:00

72 lines
2.4 KiB
C++

#include "dlg_edit_password.h"
#include "settingscache.h"
#include "stringsizes.h"
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QMessageBox>
DlgEditPassword::DlgEditPassword(QWidget *parent) : QDialog(parent)
{
oldPasswordLabel = new QLabel(tr("Old password:"));
oldPasswordEdit = new QLineEdit();
oldPasswordEdit->setMaxLength(MAX_NAME_LENGTH);
auto &servers = SettingsCache::instance().servers();
if (servers.getSavePassword()) {
oldPasswordEdit->setText(servers.getPassword());
}
oldPasswordLabel->setBuddy(oldPasswordEdit);
oldPasswordEdit->setEchoMode(QLineEdit::Password);
newPasswordLabel = new QLabel(tr("New password:"));
newPasswordEdit = new QLineEdit();
newPasswordEdit->setMaxLength(MAX_NAME_LENGTH);
newPasswordLabel->setBuddy(newPasswordLabel);
newPasswordEdit->setEchoMode(QLineEdit::Password);
newPasswordLabel2 = new QLabel(tr("Confirm new password:"));
newPasswordEdit2 = new QLineEdit();
newPasswordEdit2->setMaxLength(MAX_NAME_LENGTH);
newPasswordLabel2->setBuddy(newPasswordLabel2);
newPasswordEdit2->setEchoMode(QLineEdit::Password);
QGridLayout *grid = new QGridLayout;
grid->addWidget(oldPasswordLabel, 0, 0);
grid->addWidget(oldPasswordEdit, 0, 1);
grid->addWidget(newPasswordLabel, 1, 0);
grid->addWidget(newPasswordEdit, 1, 1);
grid->addWidget(newPasswordLabel2, 2, 0);
grid->addWidget(newPasswordEdit2, 2, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(actOk()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Change password"));
setFixedHeight(sizeHint().height());
setMinimumWidth(300);
}
void DlgEditPassword::actOk()
{
// TODO this stuff should be using qvalidators
if (newPasswordEdit->text().length() < 8) {
QMessageBox::critical(this, tr("Error"), tr("Your password is too short."));
return;
} else if (newPasswordEdit->text() != newPasswordEdit2->text()) {
QMessageBox::warning(this, tr("Error"), tr("The new passwords don't match."));
return;
}
accept();
}