关于node.js:来自Node的Postgres md5认证

Postgres md5 authentication from Node

我正在尝试使用md5身份验证方法通过节点连接到postgres。

我的pg_hba_conf文件如下所示:

1
2
3
4
5
6
"local" IS FOR Unix DOMAIN socket connections ONLY
 LOCAL   ALL           ALL                                      md5
 IPv4 LOCAL connections:
 host    ALL             ALL            127.0.0.1/32            md5
 IPv6 LOCAL connections:
 host    ALL             ALL            ::1/128                 md5

我可以通过psql连接到数据库而没有任何问题,但是我的问题是,当通过md5时,如何在节点内创建连接字符串以连接到postgres?如果我将pg_hba.conf更改为使用"密码"作为身份验证方法,则可以使用以下命令连接到数据库:

1
let connectionString = postgres://USER:password@localhost:5432/DATABASE';

我曾经以为我可以在connectionString中md5hash我的密码,例如:

1
2
3
let password = crypto.createHash('md5').update(my_password).digest('hex');

let connectionString = 'postgres://user:' + password + '@localhost:5432/database';

但是这不起作用:-(

有人可以为我指出正确的方向,说明如何使用md5身份验证通过Node访问Postgres吗?

干杯


使用:

1
let connectionString = 'postgres://user:' + my_password + '@localhost:5432/database';

文档说:

1
var client = NEW Client('postgres://brian:mypassword@localhost:5432/dev');

它根本没有提到md5。编码并发送正确编码的密码是数据库驱动程序的工作。