Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pg-password-util to wiki #3164

Open
sehrope opened this issue Mar 6, 2024 · 0 comments
Open

Add pg-password-util to wiki #3164

sehrope opened this issue Mar 6, 2024 · 0 comments

Comments

@sehrope
Copy link
Contributor

sehrope commented Mar 6, 2024

Please add pg-password-util to the wiki: https://www.npmjs.com/package/pg-password-util

It's a standalone lib that handles encoding PostgreSQL passwords client-side so that CREATE USER ... / ALTER USER ... statements do not include the plaintext of passwords in your application logs. It includes TypeScript type declarations as well.

So it replaces SQL like this being sent to your DB:

ALTER USER app PASSWORD 'Super Duper Secret!'

With SQL like this:

ALTER USER app PASSWORD 'SCRAM-SHA-256$4096:M1A3zTFR9TzaX5NuvytilQ==$TZtMCtrZ8wkkZVkS7vursem77PsBqthl8GqkPohscJw=:POfEEJ9BOrm6upeAFKU3awWqMg+kKYXyPOG5E5tuhJc='

It defaults to using SCRAM-SHA-256 for the encoding but also supports md5 for older versions of PG. It also includes a helper to change a user's password using whatever the database says is the preferred encoding (i.e. SCRAM-SHA-256 for anything 10+ and md5 for anything older):

// client is a pg.Client
await alterUserPassword(client, {
    username: 'app',
    password: 'my-new-secret-password',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant