2023-04-18 14:14:46 +08:00
|
|
|
#include "changepasswordform.h"
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
2023-05-15 16:06:10 +08:00
|
|
|
#include <QDialogButtonBox>
|
2023-04-18 18:02:58 +08:00
|
|
|
|
2023-05-15 16:06:10 +08:00
|
|
|
ChangePasswordForm::ChangePasswordForm(QWidget *parent) : QDialog(parent) {
|
2023-04-18 14:14:46 +08:00
|
|
|
resize(240, 160);
|
2023-05-15 16:06:10 +08:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
setWindowFlag(Qt::WindowContextHelpButtonHint, 0);
|
|
|
|
#endif
|
2023-04-18 14:14:46 +08:00
|
|
|
auto vBox = new QVBoxLayout(this);
|
|
|
|
auto hBox = new QHBoxLayout();
|
|
|
|
auto label = new QLabel(tr("Old password"));
|
|
|
|
hBox->addWidget(label);
|
|
|
|
|
|
|
|
fdOld = new QLineEdit();
|
|
|
|
fdOld->setEchoMode(QLineEdit::Password);
|
|
|
|
fdOld->setMaxLength(16);
|
|
|
|
hBox->addWidget(fdOld);
|
|
|
|
vBox->addLayout(hBox);
|
|
|
|
|
|
|
|
hBox = new QHBoxLayout();
|
|
|
|
auto label_2 = new QLabel(tr("New password"));
|
|
|
|
hBox->addWidget(label_2);
|
|
|
|
|
|
|
|
fdNew = new QLineEdit();
|
|
|
|
fdNew->setEchoMode(QLineEdit::Password);
|
|
|
|
fdNew->setMaxLength(8);
|
|
|
|
hBox->addWidget(fdNew);
|
|
|
|
vBox->addLayout(hBox);
|
|
|
|
|
|
|
|
hBox = new QHBoxLayout();
|
|
|
|
auto label_3 = new QLabel(tr("Repeat again"));
|
|
|
|
hBox->addWidget(label_3);
|
|
|
|
|
|
|
|
fdAgn = new QLineEdit();
|
|
|
|
fdAgn->setEchoMode(QLineEdit::Password);
|
|
|
|
fdAgn->setMaxLength(8);
|
|
|
|
hBox->addWidget(fdAgn);
|
|
|
|
vBox->addLayout(hBox);
|
|
|
|
|
2023-05-15 16:06:10 +08:00
|
|
|
auto btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
|
|
|
connect(btnBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
connect(btnBox, &QDialogButtonBox::accepted, this, [=] {
|
2023-04-18 14:14:46 +08:00
|
|
|
QString pwdOld = fdOld->text();
|
|
|
|
if(pwdOld.isEmpty()) {
|
|
|
|
QMessageBox::warning(this, tr("Tip"), tr("Please input old password"));
|
|
|
|
fdOld->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QSettings settings;
|
2023-10-23 14:58:29 +08:00
|
|
|
auto pwdRaw = settings.value("advUiPs");
|
|
|
|
QString pwd = pwdRaw.isNull() ? "888" : QString::fromUtf8(QByteArray::fromBase64(pwdRaw.toString().toLatin1()));
|
2023-04-18 14:14:46 +08:00
|
|
|
if(pwd != pwdOld) {
|
|
|
|
QMessageBox::critical(this, tr("Tip"), tr("Old password is wrong"));
|
|
|
|
fdOld->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString pwdNew = fdNew->text();
|
2023-10-23 14:58:29 +08:00
|
|
|
if(pwdNew.length() < 3 && ! pwdNew.isEmpty()) {
|
|
|
|
QMessageBox::warning(this, tr("Tip"), tr("Please enter a password with more than 3 characters"));
|
2023-04-18 14:14:46 +08:00
|
|
|
fdNew->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QString pwdAgn = fdAgn->text();
|
|
|
|
if(pwdAgn != pwdNew) {
|
|
|
|
QMessageBox::warning(this, tr("Tip"), tr("The new password is not consistent in two times"));
|
|
|
|
fdAgn->setFocus();
|
|
|
|
return;
|
|
|
|
}
|
2023-04-18 18:02:58 +08:00
|
|
|
settings.setValue("advUiPs", QString::fromLatin1(pwdNew.toUtf8().toBase64()));
|
2023-04-18 14:14:46 +08:00
|
|
|
QMessageBox::information(this, tr("Tip"), tr("Password changed successfully"));
|
|
|
|
accept();
|
|
|
|
});
|
2023-05-15 16:06:10 +08:00
|
|
|
vBox->addWidget(btnBox);
|
2023-04-18 14:14:46 +08:00
|
|
|
}
|