【问题标题】:Postgres md5 authentication from Node来自 Node 的 Postgres md5 身份验证
【发布时间】: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


【解决方案1】:

用途:

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

Documentation 说:

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

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

【讨论】:

  • 但是这个连接字符串只有在 pg_hba.conf 文件有密码的认证方法时才有效。我想使用 md5,这样密码就不会以明文形式发送。
猜你喜欢
  • 2015-08-29
  • 1970-01-01
  • 2020-09-19
  • 2019-02-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多