Skip to content

Commit 0945312

Browse files
author
jef
committedJan 7, 2010
add postgresql password cache
git-svn-id: http://svn.osgeo.org/qgis/trunk@12698 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b18b097 commit 0945312

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
5151

5252
QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRO;
5353
QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRW;
54+
QMap<QString, QString> QgsPostgresProvider::Conn::passwordCache;
5455
int QgsPostgresProvider::providerIds = 0;
5556

5657
QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
@@ -310,25 +311,36 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
310311
{
311312
QString password = QString::null;
312313

313-
while( PQstatus( pd ) != CONNECTION_OK )
314+
while ( PQstatus( pd ) != CONNECTION_OK )
314315
{
315316
bool ok = true;
316-
password = QInputDialog::getText( 0,
317-
tr( "Enter password" ),
318-
tr( "Error: %1Enter password for %2")
317+
318+
if ( passwordCache.contains( conninfo ) )
319+
{
320+
password = passwordCache.take( conninfo );
321+
}
322+
else
323+
{
324+
password = QInputDialog::getText( 0,
325+
tr( "Enter password" ),
326+
tr( "Error: %1Enter password for %2" )
319327
.arg( QString::fromUtf8( PQerrorMessage( pd ) ) )
320328
.arg( conninfo ),
321-
QLineEdit::Password,
322-
password,
323-
&ok );
324-
325-
::PQfinish( pd );
329+
QLineEdit::Password,
330+
password,
331+
&ok );
332+
}
326333

327-
if( !ok )
334+
if ( !ok )
328335
break;
329336

337+
::PQfinish( pd );
338+
330339
pd = PQconnectdb( QString( "%1 password='%2'" ).arg( conninfo ).arg( password ).toLocal8Bit() );
331340
}
341+
342+
if ( PQstatus( pd ) == CONNECTION_OK )
343+
passwordCache[ conninfo ] = password;
332344
}
333345

334346
if ( PQstatus( pd ) != CONNECTION_OK )

‎src/providers/postgres/qgspostgresprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider
660660

661661
static QMap<QString, Conn *> connectionsRW;
662662
static QMap<QString, Conn *> connectionsRO;
663+
static QMap<QString, QString> passwordCache;
663664
};
664665

665666
class Result

0 commit comments

Comments
 (0)
Please sign in to comment.