0

I have installed postgresql9.2.4 in my win7 laptop and have wrote a simple program to test the connection in my vs2008.The code is here:

#include "stdafx.h"
#include <windows.h>
#include "libpq-fe.h"


int _tmain(int argc, _TCHAR* argv[])
{
    const char *conninfo;
    PGconn     *conn;

    conninfo = "password = password";

    conn = PQconnectdb(conninfo);

    if (PQstatus(conn) != CONNECTION_OK)
    {
        printf("Connection to database failed: %s",
                PQerrorMessage(conn));
    }

    system("pause");
    return 0;
}

It showed an error that about authentication fail after ran it. I know it was the fault about password, it shoulded be md5 encrypted.So I searched in google.There almost no issue about this problem.I found a head file named "md5.h" in libpq folder and has a function named "pg_md5_hash", I tried it and came with many link error. Can anyone give me some suggestions? Thanks.

asenxu08
  • 5
  • 1
  • Details on the connection string can be found here: http://www.postgresql.org/docs/9.3/static/libpq-connect.html#LIBPQ-CONNSTRING An overall examples is here: http://www.postgresql.org/docs/devel/static/libpq-example.html – alk Sep 28 '13 at 12:59
  • I konw this document.But I have not found my answer yet. This document isn't contain anything about md5 password encrypting. – asenxu08 Sep 28 '13 at 13:12

1 Answers1

0

You don't have to encrypt password by yourself. Libpq is choosing authentication method depending on pg_hba.conf configuration.

Your conninfo is far from proper. You provided password, but you missed at least database and user name.

Tomasz Myrta
  • 1,114
  • 8
  • 10
  • I added user's name in conninfo and it passed correctly.Thank you for your kindly suggestion.It was the first time using postgresql for my project. – asenxu08 Sep 28 '13 at 13:52