Skip to content

Commit dece451

Browse files
authoredSep 29, 2023
Merge pull request #54706 from Gustry/hide-password
Hide password instead of removing it
2 parents 136cf92 + 29b08c7 commit dece451

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed
 

‎python/core/auto_generated/qgsmaplayer.sip.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,14 @@ or other problem. Child classes set this flag when initialized.
542542
:return: ``True`` if the layer is valid and can be accessed
543543
%End
544544

545-
QString publicSource() const;
545+
QString publicSource( bool hidePassword = false ) const;
546546
%Docstring
547547
Gets a version of the internal layer definition that has sensitive
548548
bits removed (for example, the password). This function should
549549
be used when displaying the source name for general viewing.
550550

551+
:param hidePassword: False, if the password should be removed or replaced by an arbitrary string, since QGIS 3.34
552+
551553
.. seealso:: :py:func:`source`
552554
%End
553555

‎src/core/project/qgsprojectbadlayerhandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void QgsProjectBadLayerHandler::handleBadLayers( const QList<QDomNode> &layers )
2828

2929
for ( const QDomNode &layer : layers )
3030
{
31-
QgsMessageLog::logMessage( QObject::tr( " * %1" ).arg( QgsDataSourceUri::removePassword( dataSource( layer ) ) ) );
31+
QgsMessageLog::logMessage( QObject::tr( " * %1" ).arg( QgsDataSourceUri::removePassword( dataSource( layer ), true ) ) );
3232
}
3333
}
3434

‎src/core/qgsmaplayer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@ QString QgsMapLayer::metadataUrlFormat() const
342342
}
343343
}
344344

345-
QString QgsMapLayer::publicSource() const
345+
QString QgsMapLayer::publicSource( bool hidePassword ) const
346346
{
347347
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
348348

349349
// Redo this every time we're asked for it, as we don't know if
350350
// dataSource has changed.
351-
QString safeName = QgsDataSourceUri::removePassword( mDataSource );
351+
QString safeName = QgsDataSourceUri::removePassword( mDataSource, hidePassword );
352352
return safeName;
353353
}
354354

‎src/core/qgsmaplayer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -564,9 +564,10 @@ class CORE_EXPORT QgsMapLayer : public QObject
564564
* Gets a version of the internal layer definition that has sensitive
565565
* bits removed (for example, the password). This function should
566566
* be used when displaying the source name for general viewing.
567+
* \param hidePassword False, if the password should be removed or replaced by an arbitrary string, since QGIS 3.34
567568
* \see source()
568569
*/
569-
QString publicSource() const;
570+
QString publicSource( bool hidePassword = false ) const;
570571

571572
/**
572573
* Returns the source for the layer. This source may contain usernames, passwords

‎src/gui/qgscredentialdialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void QgsCredentialDialog::requestCredentials( const QString &realm, QString *use
149149
stackedWidget->setCurrentIndex( 0 );
150150
mIgnoreButton->show();
151151
chkbxPasswordHelperEnable->setChecked( QgsApplication::authManager()->passwordHelperEnabled() );
152-
labelRealm->setText( QgsDataSourceUri::removePassword( realm ) );
152+
labelRealm->setText( QgsDataSourceUri::removePassword( realm, true ) );
153153
mRealm = realm;
154154
leUsername->setText( *username );
155155
lePassword->setText( *password );

0 commit comments

Comments
 (0)
Please sign in to comment.