knetattach: implement option to specify password

security wise it is bad idea to store the password as is but it is the only
way to save and connect to connection that requires password right now
because the connection is verified (see KNetAttach::doConnectionTest())

the option to not save the connection and a big warning are in place tho

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-06-05 14:58:27 +03:00
parent eb951e3ed4
commit f879fe9a4d
2 changed files with 87 additions and 43 deletions

View file

@ -48,6 +48,7 @@ KNetAttach::KNetAttach( QWidget* parent )
connect(_recent, SIGNAL(toggled(bool)), _recentConnectionName, SLOT(setEnabled(bool)));
connect(_connectionName, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_user, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_pass, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_host, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_path, SIGNAL(textChanged(QString)), this, SLOT(updateParametersPageStatus()));
connect(_createIcon, SIGNAL(toggled(bool)), this, SLOT(updateFinishButtonText(bool)));
@ -102,6 +103,13 @@ void KNetAttach::updateParametersPageStatus()
!_path->text().trimmed().isEmpty() &&
!_connectionName->text().trimmed().isEmpty()
);
if (_createIcon->isChecked() && !_pass->text().trimmed().isEmpty()) {
_createIcon->setIcon(KIcon("dialog-warning"));
_createIcon->setToolTip(i18n("The plain password will be stored"));
} else {
_createIcon->setIcon(QIcon());
_createIcon->setToolTip(QString());
}
}
bool KNetAttach::validateCurrentPage()
@ -146,6 +154,7 @@ bool KNetAttach::validateCurrentPage()
KUrl u(group.readEntry("URL"));
_host->setText(u.host());
_user->setText(u.user());
_pass->setText(u.password());
_path->setText(u.path());
if (group.hasKey("Port")) {
_port->setValue(group.readEntry("Port",0));
@ -175,6 +184,7 @@ bool KNetAttach::validateCurrentPage()
url.setHost(_host->text().trimmed());
url.setUser(_user->text().trimmed());
url.setPassword(_pass->text().trimmed());
QString path = _path->text().trimmed();
// could a relative path really be made absolute by simply prepending a '/' ?
if (!path.startsWith('/')) {
@ -194,6 +204,7 @@ bool KNetAttach::validateCurrentPage()
QString name = _connectionName->text().trimmed();
// SECURITY: plain password will be stored
if (_createIcon->isChecked()) {
KGlobal::dirs()->addResourceType("remote_entries", "data", "remoteview");
@ -259,6 +270,8 @@ bool KNetAttach::updateForProtocol(const QString& protocol)
_port->show();
_userText->show();
_user->show();
_passText->show();
_pass->show();
_encodingText->show();
_encoding->show();
} else if (protocol == "SFTP") {
@ -266,6 +279,8 @@ bool KNetAttach::updateForProtocol(const QString& protocol)
_port->show();
_userText->show();
_user->show();
_passText->show();
_pass->show();
_encodingText->hide();
_encoding->hide();
} else {

View file

@ -144,6 +144,25 @@
</property>
</widget>
</item>
<item row="1" column="2">
<spacer name="spacer20_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>282</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" colspan="2">
<widget class="KLineEdit" name="_connectionName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="textLabel4_2">
<property name="text">
@ -176,25 +195,6 @@
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="KLineEdit" name="_connectionName"/>
</item>
<item row="1" column="2">
<spacer name="spacer20_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>282</width>
<height>18</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1" colspan="2">
<widget class="KLineEdit" name="_user">
<property name="sizePolicy">
@ -206,6 +206,35 @@
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="_passText">
<property name="text">
<string>&amp;Password:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_pass</cstring>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="KLineEdit" name="_pass">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="passwordMode">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="textLabel1">
<property name="text">
<string>Se&amp;rver:</string>
@ -221,7 +250,7 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<item row="5" column="1" colspan="2">
<widget class="KLineEdit" name="_host">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -231,7 +260,7 @@
</property>
</widget>
</item>
<item row="5" column="0">
<item row="6" column="0">
<widget class="QLabel" name="_portText">
<property name="text">
<string>&amp;Port:</string>
@ -247,23 +276,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>&amp;Folder:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_path</cstring>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<widget class="KIntSpinBox" name="_port">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
@ -282,10 +295,26 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="7" column="0">
<widget class="QLabel" name="textLabel3">
<property name="text">
<string>&amp;Folder:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="buddy">
<cstring>_path</cstring>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="KLineEdit" name="_path"/>
</item>
<item row="7" column="0">
<item row="8" column="0">
<widget class="QLabel" name="_encodingText">
<property name="enabled">
<bool>true</bool>
@ -301,10 +330,10 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="8" column="1">
<widget class="KComboBox" name="_encoding"/>
</item>
<item row="8" column="1" colspan="2">
<item row="9" column="1" colspan="2">
<widget class="QCheckBox" name="_createIcon">
<property name="text">
<string>Cr&amp;eate an icon for this remote folder</string>
@ -314,7 +343,7 @@
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<item row="10" column="0" colspan="3">
<spacer name="spacer5">
<property name="orientation">
<enum>Qt::Vertical</enum>