【问题标题】:node-postgres UTF password bugnode-postgres UTF 密码错误
【发布时间】:2016-12-07 06:16:20
【问题描述】:

我正在使用 https://github.com/brianc/node-postgres pg 模块。显然我不能使用 Unicode 密码连接到数据库。从具有连接参数的同一位置psql 正常。使用 Node.js,它提供了 ne password authentication failed for user。当我与console.log() 核对时,我看到的正是我所期望的。如果我在数据库和连接字符串中都将密码更改为 ASCII,一切正常。但我需要使用旧的 Unicode 密码...

我都试过https://github.com/brianc/node-postgres/wiki/Client

new pg.Client({...password: Código

conString = "postgres://...Código@"

我知道 ODBC (Driver={PostgreSQL UNICODE};) 和 JDBC (;Unicode=true) 在连接字符串中都支持 UTF。我在 Node.js pg 模块 UTF 支持上一无所获。

请帮忙。

我看到了http://www.connectionstrings.com/postgresql/ 并阅读了https://github.com/brianc/node-postgres 上的文档。请帮忙解答问题。

谢谢!

【问题讨论】:

标签: node.js postgresql unicode node-postgres


【解决方案1】:

/lib/client.js 中发现一个错误:crypto.createHash('md5').update('утфUTF').digest('hex') 给出:

a77b17c858d93bf7455211a629df45f8

而正确的 md5 是:

a=#select md5('утфutf');
               md5
----------------------------------
 6dbfa2a80226f7629e537268b0650898
(1 row)

所以crypto.createHash('md5').update('утфutf', 'utf-8').digest('hex') 给了

6dbfa2a80226f7629e537268b0650898

接下来

加密模块使用的默认编码通常是来自another answer的“二进制”

修复了我的 utf 密码问题。所以我创建了 PR - 也许很快它就不再是问题了。

https://github.com/brianc/node-postgres/pull/1178

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 2021-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多