Skip to content

"Password authentication failed for user" error after the upgrade to 2.6.0 #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
peterliapin opened this issue Jun 23, 2016 · 13 comments
Closed
Assignees

Comments

@peterliapin
Copy link

After the upgrade to 2.6.0 I can not run my loopback project with loopback-connector-postgresql anymore.

Here is the error I get:

Connection fails: { error: password authentication failed for user "Lyapin" at Connection.parseE (\node_modules\pg\lib\connection.js:543:11) at Connection.parseMessage (\node_modules\pg\lib\connection.js:370:17) at Socket.<anonymous> (\node_modules\pg\lib\connection.js:109:22) at emitOne (events.js:96:13) at Socket.emit (events.js:188:7) at readableAddChunk (_stream_readable.js:172:18) at Socket.Readable.push (_stream_readable.js:130:10) at TCP.onread (net.js:542:20) name: 'error', length: 95, severity: 'FATAL', code: '28P01', detail: undefined, hint: undefined, position: undefined, internalPosition: undefined, internalQuery: undefined, where: undefined, schema: undefined, table: undefined, column: undefined, dataType: undefined, constraint: undefined, file: 'auth.c', line: '285', routine: 'auth_failed' }

I use Windows and it looks like with the new version of the connector (which has pg library updated from 4.2.0 to 6.0.0 as well) it tries to use my current user's windows credentials to connect to postgresql instead of the credentials specified in the datasources.json file.

If i use 2.5.0 it works as expected.

@peterliapin peterliapin changed the title Password authentication failed for user after the upgrade to 2.6.0 "Password authentication failed for user" error after the upgrade to 2.6.0 Jun 23, 2016
@raymondfeng
Copy link
Contributor

How does your ds config look like?

@peterliapin
Copy link
Author

peterliapin commented Jun 23, 2016

{
  "pg": {
    "host": "localhost",
    "port": 5432,
    "url": "postgres://user:password@localhost/database",
    "database": "database",
    "password": "password",
    "name": "pg",
    "user": "user",
    "connector": "postgresql"
  }
}

@raymondfeng
Copy link
Contributor

Can you try the following within your app?

 c:> node
> var P = require('pg/lib/connection-parameters')
> var c = new P("postgres://user:password@localhost/database")
undefined
> c

What is your printout?

@raymondfeng
Copy link
Contributor

You can also use SET DEBUG=loopback:connector:postgresql and run your app to see what settings are used.

@peterliapin
Copy link
Author

Here is what I get:

{
"user":"user",
"database":"database",
"port":5432,
"host":"localhost",
"password":"password",
"binary":false,
"ssl":false,
"client_encoding":"",
"isDomainSocket":false
}

I tried both 2.5.0 and 2.6.0 and I get exactly the same result.

@peterliapin
Copy link
Author

peterliapin commented Jun 23, 2016

I have also tried with the SET DEBUG=loopback:connector:postgresql - results are the same for both versions of the connector:

{
"host":"localhost",
"port":5432,
"url":"postgres://user:password@localhost/database",
"database":"database",
"password":"password",
"name":"pg",
"user":"postgres",
"connector":"postgresql",
"debug":true
}

raymondfeng pushed a commit that referenced this issue Jun 23, 2016
raymondfeng pushed a commit that referenced this issue Jun 23, 2016
 * Fix for #145 (Raymond Feng)
@raymondfeng
Copy link
Contributor

Should be fixed now by 2.6.1

@peterliapin
Copy link
Author

Nope, I have 2.6.1 now and it is still not working.

@raymondfeng
Copy link
Contributor

Hmm, I verified it on both Windows and Mac. One of my tests fails before the fix and works now. It's due to the usage of url.

@ssh24
Copy link
Contributor

ssh24 commented Jul 13, 2017

This is not an issue anymore. You can specify the password as a part of the url or as a config and authentication works.

Here is a sample reproduction:

datasources.json

{
  "postgresqlDs": {
    "host": "localhost",
    "port": 5432,
    "url": "",
    "database": "testdb",
    "password": "<pass>",
    "name": "postgresqlDs",
    "user": "<user>",
    "connector": "postgresql"
  },
  "newDs": {
    "host": "",
    "port": 5432,
    "url": "postgres://<user>:<pass>@localhost/testdb",
    "database": "",
    "password": "",
    "name": "newDs",
    "user": "",
    "connector": "postgresql"
  }
}

boot-script.js

'use strict';
var util = require('util');
var _ = require('lodash');

module.exports = function(app) {
    var db = app.datasources.postgresqlDs;
    var db2 = app.datasources.newDs;

    db.ping(function(err) {
        if (err) throw err;
        console.log('\nPinged first db.');

        db2.ping(function(err) {
            if (err) throw err;
            console.log('\nPinged second db.');
        });
    });
};

output

sakibs-mac:postgresql-145 ssh$ node .
Web server listening at: http://0.0.0.0:3000
Browse your REST API at http://0.0.0.0:3000/explorer

Pinged first db.

Pinged second db.

@ssh24 ssh24 closed this as completed Jul 13, 2017
@ssh24 ssh24 added this to the Sprint 40 - Apex milestone Jul 13, 2017
@johnhaire89
Copy link

johnhaire89 commented Nov 27, 2019

I installed nodejs and loopback 4 on Windows 10 today and experienced this issue.
After running npm update pg and including the credentials in the URL it's using the correct username.

>npm ls loopback-connector-postgresql

[email protected] C:\dev/first-loopback-api
`-- [email protected]

>lb4 --version

@loopback/cli version: 1.26.0

@loopback/* dependencies:
  - @loopback/authentication: ^3.2.3
  - @loopback/boot: ^1.5.12
  - @loopback/build: ^2.1.0
  - @loopback/context: ^1.24.0
  - @loopback/core: ^1.11.0
  - @loopback/metadata: ^1.3.8
  - @loopback/openapi-spec-builder: ^1.2.19
  - @loopback/openapi-v3: ^1.10.2
  - @loopback/repository-json-schema: ^1.11.2
  - @loopback/repository: ^1.15.5
  - @loopback/rest: ^1.24.0
  - @loopback/testlab: ^1.9.5
  - @loopback/docs: ^2.6.0
  - @loopback/example-hello-world: ^1.2.20
  - @loopback/example-log-extension: ^1.2.20
  - @loopback/example-rpc-server: ^1.2.20
  - @loopback/example-todo: ^1.9.1
  - @loopback/example-soap-calculator: ^1.7.1
  - @loopback/service-proxy: ^1.3.12
  - @loopback/http-caching-proxy: ^1.2.2
  - @loopback/http-server: ^1.4.19
  - @loopback/example-todo-list: ^1.12.1
  - @loopback/dist-util: ^0.4.0
  - @loopback/rest-explorer: ^1.4.5
  - @loopback/eslint-config: ^4.1.5
  - @loopback/example-express-composition: ^1.9.1
  - @loopback/example-greeter-extension: ^1.3.20
  - @loopback/booter-lb3app: ^1.3.6
  - @loopback/example-lb3-application: ^1.1.20
  - @loopback/example-greeting-app: ^1.2.6
  - @loopback/example-context: ^1.2.20
  - @loopback/repository-tests: ^0.7.0
  - @loopback/extension-health: ^0.2.12
  - @loopback/authorization: ^0.4.5
  - @loopback/rest-crud: ^0.6.1
  - @loopback/security: ^0.1.8
  - @loopback/authentication-passport: ^1.0.5
  - @loopback/example-metrics-prometheus: ^0.1.1
  - @loopback/extension-metrics: ^0.1.1

@bajtos
Copy link
Member

bajtos commented Nov 29, 2019

@johnhaire89 can you reproduce the problem using loopback-connector-postgresql version 4.0.0? If yes, then please:

@loopbackio loopbackio locked as resolved and limited conversation to collaborators Nov 29, 2019
@bajtos
Copy link
Member

bajtos commented Dec 5, 2019

@johnhaire89 sorry for the confusion, I see that the latest version of loopback-connector-postgresql is 3.8.0 and that's the version you tried & reproduced the problem with.

To help us to help you, please create a small application we can use to reproduce the problem and open a new issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants