Setup
A server running a PostgreSQL database and an Apache with several php applications. Access to db is over the loopback interface. The db contains a table with the username and SHA-512-CRYPT password hash ($6$salt$hash
).
Common solution
Applications read password from user, hash it and do a string comparison on the database. If strings match, user is authenticated.
My solution
The database has a stored function(or prepared statement?) check_password(user, password)
which php applications query with SQL. So they send the user and password in clear and interpret the db's answer (e.g. rows returned). This has the advantage that I don't have to make sure that all the applications support the same secure hash algorithm and I can encapsulate the authentication in a single place in the db. The same could be done for password changes update_password(user, old_password, new_password)
.
Are there any drawbacks to this solution?
EDIT: Added clarification on stored password format.