Miguel Lopes Martins
Miguel Lopes Martins

Reputation: 97

Connecting to Oracle via ODBC when password expired

Our company has a C++ library that internally uses ODBC APIs, and in particular the SQLConnect function to connect to our Oracle database.

Let's suppose, however, that I set a user's password (using an external tool such as PL/SQL Developer) to expired. All of a sudden, the following invocation fails...

SQLConnect("<My DSN>", "The user whose password has expired", "The expired password");

...with a return code of -1 (and rightfully so).

My question is: is it possible to allow the very same user to temporarily connect, via SQLConnect (or perhaps some other ODBC function) to our Oracle database for the sole purpose of changing their password? That is, without connecting as SYSDBA or similar...

Upvotes: 1

Views: 1124

Answers (2)

Niederee
Niederee

Reputation: 4295

To reset the password once it is expired and throwing error ORA-28001: the password has expired I change it in SQL*Plus

Launch Sql Plus from command line:

sqlplus username/password@host:port/service

You will then be prompted to set a new password.
Update your DSN and you are all set. enter image description here

Upvotes: 0

Miguel Lopes Martins
Miguel Lopes Martins

Reputation: 97

We have come to the conclusion that no ODBC function exists such that it changes the user's password when said user had been marked as expired; the ODBC API, though powerful on its own, is insufficient for this purpose.

As such, we took a different approach: since we are using Oracle 11g and our machines have Oracle Instant Client installed, we resorted to using OCI (Oracle Call Interface), in particular its OCIPasswordChange function.

sword password_change_status = OCIPasswordChange(svchp, errhp, (CONST text *)sUser, strlen(sUser), (CONST text *)sOldPassword, strlen(sOldPassword), (CONST text *)sNewPassword, strlen(sNewPassword), OCI_AUTH);

Naturally, there's probably a handful of other alternatives, such as creating a functional database user and using this user to change another user's password, but this approach works nicely.

Upvotes: 1

Related Questions