Take the 2-minute tour ×

I am new to using postgresql along with php, but something doesn't seem right here. 9/10 examples I've seen using sets the password parameter in plain text.

For example, here's one sample

$con = pg_connect("host='localhost' dbname='testdb' user='postgres' password='password');

Is this common practice? Does this pose as a security risk? If so, Is there a better way to pass the password value?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

It is a common practice. Do ensure the server is secure and you can also enable postgres to listen on SSL so that the plain text password in transit is encrypted. You can also hash the password and send it to postgres. See the link below about auth methods.

See this for more information -- http://stackoverflow.com/questions/97984/how-to-secure-database-passwords-in-php

If you are very concerned about security, postgres allows more security via multiple ways. See here -- http://www.postgresql.org/docs/9.1/static/auth-methods.html

share|improve this answer
You know, I was debating which SE site to post this. The stackoverflow link is very helpul. Thanks! –  hydroparadise Aug 13 '12 at 19:25
add comment

If you didn't use the plaintext password, because there is no challenge in this case, whatever token you used might as well be the password from an attacker's standpoint (even if it is a hash, it is all you need to authenticate). If you are concerned about security, encapsulate the database connection in SSL.

share|improve this answer
add comment

Your Answer


