Providing a Password using connParams()
You can enable your application to request a password via the connParams() callback rather than passing it directly in the RWDBManager::database() call. This option may provide increased security as it avoids storing the password in memory and instead requests it using the callback only when needed. This method takes all the parameters to establish a database connection, but all parameters except password are const so cannot be changed:
virtual void
connParams (const RWCString &serverName, const RWCString &userName,
RWCString &password, const RWCString &databaseName,
const RWCString &propertyString)
To use this API, define a database callback class as usual derived from
RWDBDatabaseCallbackImp, then implement its
connParams() method to retrieve the database password to use while establishing a connection.
For example:
class MyDBCallback: public RWDBDatabaseCallbackImp
{
public:
// Constructors
MyDBCallback() {...}
...
virtual void connParams(const RWCString& dbServer, // server name
const RWCString& username, // username
RWCString& password, // password
const RWCString& databaseName, // database name
// string used for access module specific properties
const RWCString& propertyString)
{
// user function to retrieve the password
password = getThePassword();
}
...
};
Provide this callback to the
RWDBManager’s
database() function when connecting to the database, and SourcePro DB will invoke the callback you implemented to retrieve the password.
RWDBDatabase myDbase = RWDBManager::database(
"accesslib", "servername", "username",
"password", "databasename",
RWDBDATABASECALLBACK(MyDBCallback));