致命! 用户postgres的身份验证失败,操作系统倍数,无效

致命! 用户postgres的身份验证失败,操作系统倍数,无效

问题描述:

This is my first time with Apache, php and postgresql. This is what I did:

  • I installed postgresql, wapp y pgadmin3,
  • I copied the file with my project in apache/htdocs,
  • open the index and try to enter in the user account of my web, but it said:

"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08006] [7] FATAL: the authentication failed for the user «'postgres'»' in C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\formss\class\connection.php:31 Stack trace: #0 C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\class\connection.php(31): PDO->__construct('pgsql:host=127....', ''postgres'', ''12345'') #1 C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\actions\user_login.php(6): connection->__construct() #2 {main} thrown in C:\Bitnami\wappstack-5.5.27-0\apache2\htdocs\PROJECT\forms\class\conection.php on line 31"

The pass that I set for the user postgress was 12345 in every step. Pgadmin3 let me change everything inside the db.

I already tried all these in Ubuntu but without a stack, it said the same. I checked the config of postgresql and see that for all the users say md5 like a lot of people suggest in other questions about this (yes, I searched and tried many solutions but they did not work for me).

The REAL problem is that with the exact same file, the project works in my office, with windows 7, now, with a clean installation of W7 and Ubuntu 14.04, don't want anything.

This is the connection code:

 <?php
    class connection {
        private $database;
        private $host;
        private $port;
        private $user;
        private $pass;
        public $db;
        public function __construct(){
            $this->user='postgres';
            $this->pass='12345';
            $this->host='localhost';
            $this->database='project';
            $this->port=5432;
            $this->db=new PDO("pgsql:host=".$this->host.
                ";port=".$this->port.
                ";dbname=".$this->database
                ,"'".$this->user."'"
                ,"'".$this->pass."'");
            $this->db->exec("SET CHARACTER SET utf8");
            return $this->db;
        }
        public function __clone(){
            trigger_error('The clone is not allowed', E_USER_ERROR);
        }
    }
?>

As per the comment discussion, the code that creates the database connection seems to be problematic:

        $this->db=new PDO("pgsql:host=".$this->host.
            ";port=".$this->port.
            ";dbname=".$this->database
            ,"'".$this->user."'"
            ,"'".$this->pass."'");

It is very unusual to wrap the username and password in quote marks, I have never see this before. We discovered in the comments that removing the quotes got the connection working again.

You may wish to discuss with a colleague why the database server in the office works with this unusual approach. It is possible that user accounts are disabled in some fashion, perhaps because it is a LAN-only database, and all connections are permitted.

It is also worth approaching the author of this code, in case they have some knowledge about the system that you do not. I would expect this unusual code to have been commented, so discussing it may be the next best thing.