[Previous entry: "The right way to secure a database"] [Next entry: "Two sets of slides added from Helsinki and Wolverhampton"]
Checking if a password is valid using SQL
May 11th, 2009 by Pete
Post to del.icio.us
Post to Furl
A question was posted on the Oak table mailing list some time back asking if its possible to validate a users password from within the database without creating a session. One of the replies suggested looking at my PL/SQL based password cracker. I didn't have the time to go further with it at the time as I was very busy. Then two or three of weeks ago someone else posted a question to my Oracle security forum "Verify oracle username and password using sql" that is very similar to the oaktable question.
So last weekend I spent 15 minutes extracting the code from the PL/SQL cracker and making it into an installable function. I have created a function called "testpwd" and its available in a file called testpwd.sql and also available via my Oracle security tools page. The function is easy to use. Simply create a user, grant CREATE SESSION, CREATE PROCEDURE and as SYS GRANT SELECT ON SYS.USER$ to the user and install the function. Then test it. The set up is shown here:
|
Then its simple to test the function. Imagine you want to verify that SCOTT's password is TIGER - which it is in this database then the function simply returns "Y" and then if a wrong password, in this case BLOB is passed the function returns "N". This means that the function can be used to verify passwords. Here is the sample test:
|
We can now do what is possible inside the password verification function but outside that function. If you change passwords and want to check whether the same password is reused in a password verification function this is done because both the old and new passwords are available to test. This is not the case anywhere else and sometimes it is desirable to be able to verify old and new passwords.
Hopefully this function is useful?




May 11th, 2009 at 04:46 pm
Kennie Nybo Pontoppidan says:
Dear mr. Finnigan
Great function, I really enjoy your posts.
You might want to include a few calls to the upper function before checking the username/password OR include a comment in the code, that input should be in upper case as the following test shows.
Best wishes,
Kennie Nybo Pontoppidan
SQL> create user pete identified by pete;
User created.
SQL> select testpwd('pete', 'pete' ) from dual;
TESTPWD('PETE','PETE')
---------------------------------------------------
N
SQL> select testpwd('PETE', 'pete' ) from dual;
TESTPWD('PETE','PETE')
---------------------------------------------------
N
SQL> select testpwd('pete', 'PETE' ) from dual;
TESTPWD('PETE','PETE')
---------------------------------------------------
N
SQL> select testpwd('PETE', 'PETE' ) from dual;
TESTPWD('PETE','PETE')
---------------------------------------------------
Y