21 #include "ui_setpassworddialog.h"
23 #include <QApplication>
24 #include <QPushButton>
35 connect(
ui->passwordlineEdit, SIGNAL(textChanged(QString)),
this, SLOT(
onPasswordEdit()));
36 connect(
ui->repasswordlineEdit, SIGNAL(textChanged(QString)),
this, SLOT(
onPasswordEdit()));
38 ui->body->setText(
body +
"\n\n");
39 QPushButton* ok =
ui->buttonBox->button(QDialogButtonBox::Ok);
40 ok->setEnabled(
false);
41 ok->setText(QApplication::tr(
"Ok"));
42 QPushButton* cancel =
ui->buttonBox->button(QDialogButtonBox::Cancel);
43 cancel->setText(QApplication::tr(
"Cancel"));
45 if (!extraButton.isEmpty()) {
46 QPushButton* third =
new QPushButton(extraButton);
47 ui->buttonBox->addButton(third, QDialogButtonBox::YesRole);
48 connect(third, &QPushButton::clicked,
this, [&]() { this->done(
Tertiary); });
59 QString pswd =
ui->passwordlineEdit->text();
62 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
64 }
else if (pswd.length() < 6) {
65 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
66 ui->body->setText(
body + tr(
"The password is too short."));
67 }
else if (pswd !=
ui->repasswordlineEdit->text()) {
68 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
69 ui->body->setText(
body + tr(
"The password doesn't match."));
71 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
85 for (QChar c : pass) {
87 fscore += 5. / charCounts[c];
91 variations += pass.contains(QRegExp(
"[0-9]", Qt::CaseSensitive, QRegExp::RegExp)) ? 1 : 0;
92 variations += pass.contains(QRegExp(
"[a-z]", Qt::CaseSensitive, QRegExp::RegExp)) ? 1 : 0;
93 variations += pass.contains(QRegExp(
"[A-Z]", Qt::CaseSensitive, QRegExp::RegExp)) ? 1 : 0;
94 variations += pass.contains(QRegExp(
"[\\W]", Qt::CaseSensitive, QRegExp::RegExp)) ? 1 : 0;
97 score += variations * 10;
99 score = std::min(score, 100);
100 score = std::max(score, 0);
107 return ui->passwordlineEdit->text();