node-postgres UTF密码错误 [英] node-postgres UTF password bug

查看:104
本文介绍了node-postgres UTF密码错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/brianc/node-postgres pg 模块。显然,我无法使用Unicode密码来连接数据库。从具有连接参数的相同位置 psql 可以正常进行。使用Node.js,它可以为用户提供个密码身份验证失败。当我检查 console.log()时,我确切地看到了我的期望。如果我在数据库和连接字符串中都将密码更改为ASCII,则一切正常。但是我需要使用旧的Unicode密码...

I'm using https://github.com/brianc/node-postgres pg module. Apparently I can't consume a Unicode password to connect to the db. From the same location psql with connection parameters goes OK. With Node.js, it gives ne password authentication failed for user. When I check with console.log() I see exactly what I expect. If I change a password to ASCII both in the db and the connection string, everything works well. But I need the old Unicode password to be consumed...

我都尝试了> https://github.com/brianc/node-postgres/wiki/Client

new pg.Client({...密码:Código

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

我知道两个ODBC(我发现 Driver = {PostgreSQL UNICODE}; )和JDBC(; Unicode = true )在连接字符串中支持UTF。 Node.js pg 模块UTF支持上没有任何内容。

I know that both ODBC (Driver={PostgreSQL UNICODE};) and JDBC (;Unicode=true) support UTF in connection string. I find nothing on Node.js pg module UTF support.

请帮助。

我看到了 http://www.connectionstrings.com/postgresql/ 和请阅读 https://github.com/brianc/node-postgres 上的文档。请帮助

I saw http://www.connectionstrings.com/postgresql/ and read the documentation on https://github.com/brianc/node-postgres. Please help with the question.

谢谢!

推荐答案

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

Found a bug in /lib/client.js: crypto.createHash('md5').update('утфUTF').digest('hex') gives:


a77b17c858d93bf7455211a629df45f8

a77b17c858d93bf7455211a629df45f8

而正确的md5为:

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

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


6dbfa2a80226f7629e537268b0650898

6dbfa2a80226f7629e537268b0650898

随后


默认加密模块使用的编码通常是另一个答案

中的二进制

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

Fixed my utf password problem. So I created PR - maybe soon it won't be a question anymore.

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

这篇关于node-postgres UTF密码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆