keepassxc

Форк
0
/
PasswordEditWidget.cpp 
132 строки · 3.9 Кб
1
/*
2
 *  Copyright (C) 2018 KeePassXC Team <team@keepassxc.org>
3
 *
4
 *  This program is free software: you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation, either version 2 or (at your option)
7
 *  version 3 of the License.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17

18
#include "PasswordEditWidget.h"
19
#include "ui_KeyComponentWidget.h"
20
#include "ui_PasswordEditWidget.h"
21

22
#include "keys/CompositeKey.h"
23
#include "keys/PasswordKey.h"
24

25
PasswordEditWidget::PasswordEditWidget(QWidget* parent)
26
    : KeyComponentWidget(parent)
27
    , m_compUi(new Ui::PasswordEditWidget())
28
{
29
    initComponent();
30
}
31

32
PasswordEditWidget::~PasswordEditWidget() = default;
33

34
bool PasswordEditWidget::addToCompositeKey(QSharedPointer<CompositeKey> key)
35
{
36
    QString pw = m_compUi->enterPasswordEdit->text();
37
    if (!pw.isEmpty()) {
38
        key->addKey(QSharedPointer<PasswordKey>::create(pw));
39
        return true;
40
    }
41
    return false;
42
}
43

44
/**
45
 * @param visible changed password visibility state
46
 */
47
void PasswordEditWidget::setPasswordVisible(bool visible)
48
{
49
    m_compUi->enterPasswordEdit->setShowPassword(visible);
50
}
51

52
/**
53
 * @return password visibility state
54
 */
55
bool PasswordEditWidget::isPasswordVisible() const
56
{
57
    return m_compUi->enterPasswordEdit->isPasswordVisible();
58
}
59

60
bool PasswordEditWidget::isEmpty() const
61
{
62
    return (visiblePage() == Page::Edit) && m_compUi->enterPasswordEdit->text().isEmpty();
63
}
64

65
PasswordHealth::Quality PasswordEditWidget::getPasswordQuality() const
66
{
67
    QString pwd = m_compUi->enterPasswordEdit->text();
68
    PasswordHealth passwordHealth(pwd);
69

70
    return passwordHealth.quality();
71
}
72

73
QWidget* PasswordEditWidget::componentEditWidget()
74
{
75
    m_compEditWidget = new QWidget();
76
    m_compUi->setupUi(m_compEditWidget);
77
    m_compUi->enterPasswordEdit->enablePasswordGenerator();
78
    m_compUi->enterPasswordEdit->setRepeatPartner(m_compUi->repeatPasswordEdit);
79
    return m_compEditWidget;
80
}
81

82
void PasswordEditWidget::initComponentEditWidget(QWidget* widget)
83
{
84
    Q_UNUSED(widget);
85
    Q_ASSERT(m_compEditWidget);
86
    m_compUi->enterPasswordEdit->setFocus();
87

88
    m_compUi->enterPasswordEdit->setQualityVisible(true);
89
    m_compUi->repeatPasswordEdit->setQualityVisible(false);
90
}
91

92
void PasswordEditWidget::initComponent()
93
{
94
    // These need to be set in total for each credential type for translation purposes
95
    m_ui->groupBox->setTitle(tr("Password"));
96
    m_ui->addButton->setText(tr("Add Password"));
97
    m_ui->changeButton->setText(tr("Change Password"));
98
    m_ui->removeButton->setText(tr("Remove Password"));
99
    m_ui->changeOrRemoveLabel->setText(tr("Password set, click to change or remove"));
100

101
    m_ui->componentDescription->setText(
102
        tr("<p>A password is the primary method for securing your database.</p>"
103
           "<p>Good passwords are long and unique. KeePassXC can generate one for you.</p>"));
104
}
105

106
void PasswordEditWidget::hideEvent(QHideEvent* event)
107
{
108
    if (!isVisible() && m_compUi->enterPasswordEdit) {
109
        m_compUi->enterPasswordEdit->setText("");
110
        m_compUi->repeatPasswordEdit->setText("");
111
    }
112

113
    QWidget::hideEvent(event);
114
}
115

116
bool PasswordEditWidget::validate(QString& errorMessage) const
117
{
118
    if (m_compUi->enterPasswordEdit->text() != m_compUi->repeatPasswordEdit->text()) {
119
        errorMessage = tr("Passwords do not match.");
120
        return false;
121
    }
122

123
    return true;
124
}
125

126
void PasswordEditWidget::setPassword(const QString& password)
127
{
128
    Q_ASSERT(m_compEditWidget);
129

130
    m_compUi->enterPasswordEdit->setText(password);
131
    m_compUi->repeatPasswordEdit->setText(password);
132
}
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.