Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 --

If you are very concerned about security, postgres allows more security via multiple ways. See here --

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

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.