Search code examples
postgresqlprotocolslibpq

How to generate an AuthenticationMD5Password message


I'm creating a postgresql client in gdscript (you can answer my question even if you don't know how to code in gdscript).

To do this I use the postgresql protocol specification

I managed to contact the server and it asks me for "AuthenticationMD5Password", but I cannot identify myself. I followed the procedure to generate the password described on the page but I get a server error.

with this sql formula that I adapted in gdscript:

concat('md5', md5(concat(md5(concat(password, username)), random-salt)))

With "password" the value "test", "username" the value "test" and "random-salt" the value "98dec364".

We obtain: md5936597c6b72ab2681ca01dca38b17da0

I get the following error: Message: password authentication failed for user "test" SQLSTATE code: 28P01

It seems to come from salt, is the format really an exadecimal string? I tried translating it to utf8 but it doesn't work, thanks in advance.


Solution

  • The salt is not 8 hexadecimal digits, it is 4 bytes. They are just binary bytes, so they don't have a character set.