Skip to content

Commit 562c9e2

Browse files
committed
Match PasswordDialog behavior like PinUnblock
Signed-off-by: Raul Metsma <raul@metsma.ee>
1 parent 066e971 commit 562c9e2

File tree

6 files changed

+106
-44
lines changed

6 files changed

+106
-44
lines changed

client/dialogs/PasswordDialog.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,38 @@ PasswordDialog::PasswordDialog(Mode mode, QWidget *parent)
3131
ui->labelLine->setReadOnly(mode == Mode::DECRYPT);
3232
ui->infoWidget->setHidden(mode == Mode::DECRYPT);
3333
ui->passwordHint->setHidden(mode == Mode::DECRYPT);
34+
ui->passwordError->hide();
3435
ui->password2Label->setHidden(mode == Mode::DECRYPT);
3536
ui->password2Line->setHidden(mode == Mode::DECRYPT);
37+
ui->password2Error->hide();
3638
if(mode == DECRYPT) {
3739
ui->passwordLabel->setText(tr("Enter password to decrypt the document"));
3840
ui->ok->setText(tr("Decrypt"));
3941
}
40-
connect(ui->ok, &QPushButton::clicked, this, &QDialog::accept);
42+
auto setError = [this](LineEdit *input, QLabel *error, const QString &msg) {
43+
input->setLabel(msg.isEmpty() ? QString() : QStringLiteral("error"));
44+
error->setFocusPolicy(msg.isEmpty() ? Qt::NoFocus : Qt::TabFocus);
45+
error->setText(msg);
46+
error->setHidden(msg.isEmpty());
47+
};
48+
connect(ui->passwordLine, &QLineEdit::textEdited, ui->passwordError, [this, setError] {
49+
setError(ui->passwordLine, ui->passwordError, {});
50+
});
51+
connect(ui->password2Line, &QLineEdit::textEdited, ui->password2Error, [this, setError] {
52+
setError(ui->password2Line, ui->password2Error, {});
53+
});
54+
connect(ui->ok, &QPushButton::clicked, this, [this, setError] {
55+
if(ui->passwordLine->text().isEmpty())
56+
return setError(ui->passwordLine, ui->passwordError, tr("Password is empty"));
57+
if(static const QRegularExpression re(QStringLiteral(R"(^(?=.{20,64}$)(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).*$)"));
58+
ui->password2Line->isVisible() && !re.match(ui->passwordLine->text()).hasMatch())
59+
return setError(ui->passwordLine, ui->passwordError, tr("Password does not meet complexity requirements"));
60+
if(ui->password2Line->isVisible() &&
61+
ui->passwordLine->text() != ui->password2Line->text())
62+
return setError(ui->password2Line, ui->password2Error, tr("Passwords do not match"));
63+
accept();
64+
});
4165
connect(ui->cancel, &QPushButton::clicked, this, &QDialog::reject);
42-
connect(ui->passwordLine, &QLineEdit::textChanged, this, &PasswordDialog::updateOK);
43-
connect(ui->password2Line, &QLineEdit::textChanged, this, &PasswordDialog::updateOK);
44-
updateOK();
4566
}
4667

4768
PasswordDialog::~PasswordDialog()
@@ -66,18 +87,3 @@ PasswordDialog::secret() const
6687
{
6788
return ui->passwordLine->text().toUtf8();
6889
}
69-
70-
void
71-
PasswordDialog::updateOK()
72-
{
73-
bool active = false;
74-
if(ui->password2Line->isVisible())
75-
{
76-
static const QRegularExpression re(QStringLiteral(R"(^(?=.{20,64}$)(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).*$)"));
77-
active = re.match(ui->passwordLine->text()).hasMatch() &&
78-
ui->passwordLine->text() == ui->password2Line->text();
79-
}
80-
else
81-
active = !ui->passwordLine->text().isEmpty();
82-
ui->ok->setEnabled(active);
83-
}

client/dialogs/PasswordDialog.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,23 @@ namespace Ui {
2525
class PasswordDialog;
2626
}
2727

28-
class PasswordDialog : public QDialog
28+
class PasswordDialog final : public QDialog
2929
{
3030
Q_OBJECT
3131

3232
public:
33-
enum Mode {
33+
enum Mode : quint8 {
3434
ENCRYPT,
3535
DECRYPT
3636
};
3737

3838
explicit PasswordDialog(Mode mode, QWidget *parent = nullptr);
39-
~PasswordDialog();
39+
~PasswordDialog() final;
4040

4141
void setLabel(const QString& label);
4242
QString label();
4343
QByteArray secret() const;
4444

4545
private:
4646
Ui::PasswordDialog *ui;
47-
48-
void genKeyClicked();
49-
void updateOK();
5047
};

client/dialogs/PasswordDialog.ui

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<x>0</x>
1111
<y>0</y>
1212
<width>496</width>
13-
<height>570</height>
13+
<height>610</height>
1414
</rect>
1515
</property>
1616
<property name="styleSheet">
@@ -23,6 +23,9 @@ font-size: 14px;
2323
background-color: #FFFFFF;
2424
border-radius: 4px;
2525
}
26+
#passwordError, #password2Error {
27+
color: #AD2A45;
28+
}
2629
QLineEdit {
2730
padding: 10px 14px;
2831
border: 1px solid #C4CBD8;
@@ -31,6 +34,9 @@ background-color: white;
3134
placeholder-text-color: #607496;
3235
font-size: 16px;
3336
}
37+
QLineEdit[label=&quot;error&quot;] {
38+
border-color: #BE7884;
39+
}
3440
QLineEdit::disabled {
3541
color: #607496;
3642
background-color: #F3F5F7;
@@ -187,12 +193,15 @@ margin-left: 6px;
187193
</widget>
188194
</item>
189195
<item>
190-
<widget class="QLineEdit" name="passwordLine">
196+
<widget class="LineEdit" name="passwordLine">
191197
<property name="echoMode">
192198
<enum>QLineEdit::Password</enum>
193199
</property>
194200
</widget>
195201
</item>
202+
<item>
203+
<widget class="QLabel" name="passwordError"/>
204+
</item>
196205
<item>
197206
<widget class="QLabel" name="passwordHint">
198207
<property name="text">
@@ -224,12 +233,15 @@ margin-left: 6px;
224233
</widget>
225234
</item>
226235
<item>
227-
<widget class="QLineEdit" name="password2Line">
236+
<widget class="LineEdit" name="password2Line">
228237
<property name="echoMode">
229238
<enum>QLineEdit::Password</enum>
230239
</property>
231240
</widget>
232241
</item>
242+
<item>
243+
<widget class="QLabel" name="password2Error"/>
244+
</item>
233245
</layout>
234246
</item>
235247
<item>
@@ -271,6 +283,13 @@ margin-left: 6px;
271283
</item>
272284
</layout>
273285
</widget>
286+
<customwidgets>
287+
<customwidget>
288+
<class>LineEdit</class>
289+
<extends>QLineEdit</extends>
290+
<header>widgets/LineEdit.h</header>
291+
</customwidget>
292+
</customwidgets>
274293
<resources>
275294
<include location="../images/images.qrc"/>
276295
</resources>

client/translations/en.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,18 @@ ID-Card</translation>
18021802
<source>Decrypt</source>
18031803
<translation>Decrypt</translation>
18041804
</message>
1805+
<message>
1806+
<source>Password is empty</source>
1807+
<translation>Password is empty</translation>
1808+
</message>
1809+
<message>
1810+
<source>Password does not meet complexity requirements</source>
1811+
<translation>Password does not meet complexity requirements</translation>
1812+
</message>
1813+
<message>
1814+
<source>Passwords do not match</source>
1815+
<translation>Passwords do not match</translation>
1816+
</message>
18051817
<message>
18061818
<source>Enter a password to encrypt the document</source>
18071819
<translation>Enter a password to encrypt the document</translation>

client/translations/et.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,18 @@ ID-kaardiga</translation>
18021802
<source>Decrypt</source>
18031803
<translation>Dekrüpteeri</translation>
18041804
</message>
1805+
<message>
1806+
<source>Password is empty</source>
1807+
<translation>Parool on tühi</translation>
1808+
</message>
1809+
<message>
1810+
<source>Password does not meet complexity requirements</source>
1811+
<translation>Parool ei vasta keerukusnõuetele</translation>
1812+
</message>
1813+
<message>
1814+
<source>Passwords do not match</source>
1815+
<translation>Paroolid ei ühti</translation>
1816+
</message>
18051817
<message>
18061818
<source>Enter a password to encrypt the document</source>
18071819
<translation>Loo ümbrikule parool</translation>

client/translations/ru.ts

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@
558558
</message>
559559
<message>
560560
<source>Unsupported file format</source>
561-
<translation type="unfinished"></translation>
561+
<translation>Неподдерживаемый формат файла</translation>
562562
</message>
563563
<message>
564564
<source>Key already exists</source>
@@ -606,19 +606,19 @@
606606
</message>
607607
<message>
608608
<source>Wrong password.</source>
609-
<translation type="unfinished"></translation>
609+
<translation>Неверный пароль.</translation>
610610
</message>
611611
<message>
612612
<source>Wrong key.</source>
613-
<translation type="unfinished"></translation>
613+
<translation>Неверный ключ.</translation>
614614
</message>
615615
<message>
616616
<source>Corrupted or tampered file.</source>
617-
<translation type="unfinished"></translation>
617+
<translation>Файл повреждён или был изменён.</translation>
618618
</message>
619619
<message>
620620
<source>Cannot read file.</source>
621-
<translation type="unfinished"></translation>
621+
<translation>Не удаётся прочитать файл.</translation>
622622
</message>
623623
</context>
624624
<context>
@@ -1247,7 +1247,7 @@
12471247
</message>
12481248
<message>
12491249
<source>Lock type</source>
1250-
<translation type="unfinished"></translation>
1250+
<translation>Тип блокировки</translation>
12511251
</message>
12521252
<message>
12531253
<source>Expiry date</source>
@@ -1344,7 +1344,7 @@ E-Seal</source>
13441344
</message>
13451345
<message>
13461346
<source>Encrypt long-term</source>
1347-
<translation type="unfinished"></translation>
1347+
<translation>Зашифровать долгосрочно</translation>
13481348
</message>
13491349
<message>
13501350
<source>Decrypt</source>
@@ -1760,27 +1760,31 @@ ID-картой</translation>
17601760
<name>PasswordDialog</name>
17611761
<message>
17621762
<source>Encrypt with password</source>
1763-
<translation type="unfinished"></translation>
1763+
<translation>Зашифровать с паролем</translation>
17641764
</message>
17651765
<message>
17661766
<source>Key label (recipient name or id)</source>
1767-
<translation type="unfinished"></translation>
1767+
<translation>Метка ключа (имя или идентификатор получателя)</translation>
17681768
</message>
17691769
<message>
17701770
<source>Be sure to save the password in a secure place
17711771
- without the password, you won’t be able to open the file again.</source>
1772-
<translation type="unfinished"></translation>
1772+
<translation>Обязательно сохраните пароль в надёжном месте
1773+
- без пароля вы не сможете открыть файл снова.</translation>
17731774
</message>
17741775
<message>
17751776
<source>• Length: 20–64 characters
17761777
• Contains at least one number (0–9)
17771778
• Contains at least one uppercase letter
17781779
• Contains at least one lowercase letter</source>
1779-
<translation type="unfinished"></translation>
1780+
<translation>• Длина: 20–64 символа
1781+
• Содержит хотя бы одну цифру (0–9)
1782+
• Содержит хотя бы одну заглавную букву
1783+
• Содержит хотя бы одну строчную букву</translation>
17801784
</message>
17811785
<message>
17821786
<source>Repeat password</source>
1783-
<translation type="unfinished"></translation>
1787+
<translation>Повторите пароль</translation>
17841788
</message>
17851789
<message>
17861790
<source>Cancel</source>
@@ -1792,15 +1796,27 @@ ID-картой</translation>
17921796
</message>
17931797
<message>
17941798
<source>Enter password to decrypt the document</source>
1795-
<translation type="unfinished"></translation>
1799+
<translation>Введите пароль для расшифровки документа</translation>
17961800
</message>
17971801
<message>
17981802
<source>Decrypt</source>
17991803
<translation>Расшифровать</translation>
18001804
</message>
1805+
<message>
1806+
<source>Password is empty</source>
1807+
<translation>Пароль пустой</translation>
1808+
</message>
1809+
<message>
1810+
<source>Password does not meet complexity requirements</source>
1811+
<translation>Пароль не соответствует требованиям сложности</translation>
1812+
</message>
1813+
<message>
1814+
<source>Passwords do not match</source>
1815+
<translation>Пароли не совпадают</translation>
1816+
</message>
18011817
<message>
18021818
<source>Enter a password to encrypt the document</source>
1803-
<translation type="unfinished"></translation>
1819+
<translation>Введите пароль для шифрования документа</translation>
18041820
</message>
18051821
</context>
18061822
<context>
@@ -2520,11 +2536,11 @@ Additional licenses and components</source>
25202536
</message>
25212537
<message>
25222538
<source>Fetch URL</source>
2523-
<translation type="unfinished"></translation>
2539+
<translation>URL для получения данных</translation>
25242540
</message>
25252541
<message>
25262542
<source>Post URL</source>
2527-
<translation type="unfinished"></translation>
2543+
<translation>URL для отправки данных</translation>
25282544
</message>
25292545
</context>
25302546
<context>

0 commit comments

Comments
 (0)