2016-10-25 26 views
0

我試圖通過使用md5身份驗證方法的節點連接到postgres。來自節點的Postgres md5身份驗證

我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:[email protected]:5432/database'; 

我原以爲我可以在如的connectionString內md5hash我的密碼:

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

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

但這並沒有工作:-(

有人點我在正確的方向,告訴你如何使用MD5認證通過節點訪問Postgres的?

個乾杯

+1

你爲什麼認爲它應該是'md5(密碼)'? – zerkms

+0

說明文檔 基於密碼的身份驗證方法是md5和密碼。除了通過連接發送密碼的方式,這些方法的操作類似,分別是MD5哈希和純文本。 所以我曾想過,如果我md5散列我的密碼,並轉發它在連接字符串postgres將能夠理解它。 – hloughrey

+0

https://www.postgresql.org/docs/devel/static/protocol-flow.html#AEN92524檢查'AuthenticationMD5Password'項目。它不像'md5(密碼)'那麼簡單。這是稍微友好的解釋:http://stackoverflow.com/a/14941263/251311 – zerkms

回答

1

用途:

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

Documentation說:

var client = new Client('postgres://brian:[email protected]:5432/dev'); 

它沒有提到的MD5的。這是數據庫驅動程序的工作,編碼和發送正確編碼的密碼。

+0

但是,此連接字符串僅適用於pg_hba.conf文件具有密碼驗證方法。我想使用md5,以便密碼不會以明文形式發送。 – hloughrey