dev333
dev333

Reputation: 799

How to change the password of postgres user using java?

I'm trying to login to postgres via admin user. How to update the password of a normal user using java?

Upvotes: 0

Views: 407

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247950

You can run

ALTER ROLE rolename PASSWORD 'newpassword'

But there is a danger there. Unless you are using an encrypted database connection, the password will be sent in clear text and may end up in the PostgreSQL log file.

So the better option is to hash the password before you send it so the server. Unfortunately the JDBC driver does not provide functions to do that, so you would have to rewrite that code in Java.

Upvotes: 3

Related Questions