Friday, April 3, 2009

How to connect as a user for a short time, without knowing the password.

Let's say you want, temporarily, to connect to your database as a user, whose password you don't know, and, perhaps, you don't want to find it out.
Furthermore, when you've finished, the user should be able to connect using the same password.
Each user's password is encrypted and stored in the database in the SYS.USER$ table, under PASSWORD column and in 11g databases this is the only place you can find it, since it was removed from DBA_USERS view [Oracle note 735651.1].
You may query the DBA_USERS to get it:
SQL> SELECT PASSWORD FROM DBA_USERS WHERE USERNAME='AARGY';
PASSWORD
----------------
5161D15AA3324F0A

Now, change user's password, so you may connect to the database using that account:
SQL> ALTER USER AARGY IDENTIFIED BY TEST_123;
User altered.

SQL> CONN AARGY/TEST_123
Connected.

You've finished and it's time to restore the password, so:
SQL> ALTER USER AARGY IDENTIFIED BY VALUES '5161D15AA3324F0A';
User altered.

SQL> CONNECT AARGY/TEST_123
ERROR:
ORA-01017: invalid username/password; logon denied

No comments:

Post a Comment