Skip to content
Permalink
Browse files
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 0945312a6bb474e1eaf830d5bdee569a66c11bd7
Showing with 23 additions and 10 deletions.
  1. +22 −10 src/providers/postgres/qgspostgresprovider.cpp
  2. +1 −0 src/providers/postgres/qgspostgresprovider.h
@@ -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 )
@@ -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 )
@@ -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

0 comments on commit 0945312

Please sign in to comment.