Documentation Home
MySQL Connector/C++ 1.1 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 282.9Kb
PDF (A4) - 285.2Kb
HTML Download (TGZ) - 54.4Kb
HTML Download (Zip) - 67.7Kb


MySQL Connector/C++ 1.1 Developer Guide  /  Connector/C++: Usage Examples  /  Connecting to an Account with an Expired Password

6.7 Connecting to an Account with an Expired Password

MySQL supports password expiration capability, as described in Password Management. If a client application connects to the MySQL user using an account with an expired password, client capabilities are limited until it resets the account password; for more information, see Server Handling of Expired Passwords.

A Connector/C++ application can reset an expired password using the OPT_CAN_HANDLE_EXPIRED_PASSWORDS and preInit connection options described in Chapter 10, Connector/C++ Connection Options. Enable the OPT_CAN_HANDLE_EXPIRED_PASSWORDS option, and supply an ALTER USER statement that sets the password as the value of the preInit option:

opts["OPT_CAN_HANDLE_EXPIRED_PASSWORDS"]= true;
opts["preInit"]= sql::SQLString("ALTER USER 'user' IDENTIFIED BY 'new-pwd';");

The ALTER USER statement sets a new password as the first thing after connecting. After connecting with these options, the new password should be established and it should be possible to use the session as usual. Any new sessions must use the new password, but they do not need the OPT_CAN_HANDLE_EXPIRED_PASSWORDS or preInit options.