【发布时间】:2016-10-26 05:07:13
【问题描述】:
我正在尝试使用 md5 身份验证方法通过节点连接到 postgres。
我的 pg_hba_conf 文件如下所示:
"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 更改为使用“密码”作为身份验证方法,那么我可以使用以下内容连接到数据库:
let connectionString = postgres://user:password@localhost:5432/database';
我曾认为我可以在 connectionString 中对我的密码进行 md5hash,例如:
let password = crypto.createHash('md5').update(my_password).digest('hex');
let connectionString = 'postgres://user:' + password + '@localhost:5432/database';
但这不起作用:-(
关于如何使用 md5 身份验证通过 Node 访问 postgres,有人能指出正确的方向吗?
干杯
【问题讨论】:
-
为什么你认为应该是
md5(password)? -
文档说基于密码的身份验证方法是 md5 和密码。除了通过连接发送密码的方式(即分别为 MD5 散列和明文)之外,这些方法的操作类似。所以我想如果我 md5 对我的密码进行哈希处理并在连接字符串中转发它,postgres 就能理解它。
-
postgresql.org/docs/devel/static/protocol-flow.html#AEN92524 检查
AuthenticationMD5Password项目。可不像md5(password)那么简单。这是稍微友好的解释:stackoverflow.com/a/14941263/251311
标签: node.js postgresql node-postgres