So, we encountered an issue where the password in our database is SCRAM-SHA-256 hashed. We confirmed this by querying pg_authid:
SELECT rolpassword FROM pg_authid
WHERE rolname = 'youruser';
This happened because the parameter password_encryption is set to scram-sha-256. Now, even though it says MD5 in pg_hba.conf, PostgreSQL uses scram-sha-256 authentication when there's a SCRAM-hashed password. This is a compatibility feature intended to ease the transition to SCRAM.
To make MD5 authentication work, we need to change the parameter password_encryption in postgresql.conf to md5, reload the database, and reset the user's password. This will give us an MD5 hashed password, enabling MD5 authentication.
However, the better solution would be to upgrade our client software. Running old software is never ideal.
Sending a hashed password won't help here; it's about the authentication method requested by the server. Our .NET provider is too old to understand the requested scram-sha-256 authentication method introduced in PostgreSQL v10.
We need to upgrade to a more recent version of our .NET provider. This will likely resolve the problem.
Additionally, we must upgrade the PostgreSQL client software used by our Rust driver to a later version supporting the scram-sha-256 authentication method introduced in PostgreSQL v10.
Specifically, we need to upgrade to Npgsql latest, which supports the scram-sha-256 authentication method available since PostgreSQL v10.
It's possible that while the database server has been upgraded, the client library used by our C# code to connect to the server hasn't. The old client library doesn't understand the new authentication method. We should try updating the Npgsql library to resolve this issue.
So, we decided to downgrade to PostgreSQL 12, and it actually helped resolve our issue. However, we should note that downgrading password_encryption in PostgreSQL to md5, changing all the passwords, and using the md5 authentication method is a possible solution, but it's not a recommended one.
This alternative requires more effort, and in the end, we get worse security and end up with old, potentially buggy software. It's generally not a good idea to compromise security and stability for the a quick fix.
It's important to consider the long-term implications and prioritize maintaining a secure and up-to-date environment. Downgrading should be a last option and only considered if absolutely necessary.