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.