Database connections / Database user authentication |
dbi.default.userauth.callback = "[module-name.]function-name"
This callback method is not a password encryption solution, it is only provided as workaround to provide a user credentials for programs using the DATABASE instructions. If possible, use the CONNECT TO instruction with the USER/USING clause instead. This callback method is provided to connect to databases different from IBM® Informix®, when a lot of existing code uses the DATABASE instruction. With the IBM Informix driver, the callback method is also called, but the user name and password are ignored by the DATABASE instruction: Only CONNECT TO will take the login parameters into account for IBM Informix.
The callback function must have the following signature:
CALL function-name(dbspec STRING) RETURNING STRING (username), STRING (password)
If you do not specify the module name, the callback function must be linked to the 42r program. By using the "module-name.function-name" syntax in the FGLPROFILE entry, the runtime system will automatically load the module. In both cases, the module must be located in a directory where the runtime system can find it, defined by the FGLLDPATH environment variable.
In the callback function body, the value of dbspec can be used to identify the database source, read user name and encrypted password from FGLPROFILE entries with the fgl_getResource() function, then decrypt password with the algorithm of your choice and return user name and decrypted password.
FUNCTION getUserAuth(dbspec) DEFINE dbspec STRING DEFINE un, ep STRING LET un = fgl_getResource("dbi.database."||dbspec||".username") LET ep = fgl_getResource("dbi.database."||dbspec||".password.encrypted") RETURN un, decrypt_user_password(dbspec, un, ep) END FUNCTION