Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add postgresql password cache
git-svn-id: http://svn.osgeo.org/qgis/trunk@12698 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 7, 2010
1 parent b18b097 commit 0945312
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -51,6 +51,7 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";

QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRO;
QMap<QString, QgsPostgresProvider::Conn *> QgsPostgresProvider::Conn::connectionsRW;
QMap<QString, QString> QgsPostgresProvider::Conn::passwordCache;
int QgsPostgresProvider::providerIds = 0;

QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
Expand Down Expand Up @@ -310,25 +311,36 @@ QgsPostgresProvider::Conn *QgsPostgresProvider::Conn::connectDb( const QString &
{
QString password = QString::null;

while( PQstatus( pd ) != CONNECTION_OK )
while ( PQstatus( pd ) != CONNECTION_OK )
{
bool ok = true;
password = QInputDialog::getText( 0,
tr( "Enter password" ),
tr( "Error: %1Enter password for %2")

if ( passwordCache.contains( conninfo ) )
{
password = passwordCache.take( conninfo );
}
else
{
password = QInputDialog::getText( 0,
tr( "Enter password" ),
tr( "Error: %1Enter password for %2" )
.arg( QString::fromUtf8( PQerrorMessage( pd ) ) )
.arg( conninfo ),
QLineEdit::Password,
password,
&ok );

::PQfinish( pd );
QLineEdit::Password,
password,
&ok );
}

if( !ok )
if ( !ok )
break;

::PQfinish( pd );

pd = PQconnectdb( QString( "%1 password='%2'" ).arg( conninfo ).arg( password ).toLocal8Bit() );
}

if ( PQstatus( pd ) == CONNECTION_OK )
passwordCache[ conninfo ] = password;
}

if ( PQstatus( pd ) != CONNECTION_OK )
Expand Down
1 change: 1 addition & 0 deletions src/providers/postgres/qgspostgresprovider.h
Expand Up @@ -660,6 +660,7 @@ class QgsPostgresProvider : public QgsVectorDataProvider

static QMap<QString, Conn *> connectionsRW;
static QMap<QString, Conn *> connectionsRO;
static QMap<QString, QString> passwordCache;
};

class Result
Expand Down

0 comments on commit 0945312

Please sign in to comment.