You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The only direct dependency is pg-format used to escape literals and identifiers.
The ALTER USER helpers accept a client argument that must provide the same signature as pg.Client (i.e. the client from the pg node-postgres driver). It's not a direct dependency of this module though.
Features
Encoding passwords using SCRAM-SHA-256 (recommended)
Encoding passwords using md5 (for legacy systems)
Generating SQL to change a user's password
Inferring the password_encryption from the target database
Usage
Generate SQL for an ALTER USER to change a password
Generate encoded password for use in a custom CREATE USER statement
import{encodeScramSha256}= require('pg-password-util');import*aspgFormatfrom'pg-format';constencodedPassword=encodeScramSha256({password: 'my-new-secret-password',iterations: 10000,});constsql=pgFormat('CREATE USER app PASSWORD %L LOGIN',encodedPassword);
Change a user's password
import{alterUserPassword}= require('pg-password-util');// client is a pg.ClientawaitalterUserPassword(client,{username: 'app',password: 'my-new-secret-password',});
Building and Testing
To build the module run:
$ make
Testing requires a PostgreSQL database. You can start one in the foreground via: