npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pg-password-util

v1.0.0

Published

Client-side encoding of PostgreSQL user passwords for use in CREATE USER and ALTER USER

Downloads

1,623

Readme

pg-password-util

NPM

Overview

Utility library for password encoding for PostgreSQL.

This solves the problem of plaintext passwords appearing in server logs by replacing:

ALTER USER app PASSWORD 'Super Duper Secret!'

With the password encoded client side:

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

That hashed value does not contain the plaintext of the password and matches how PostgreSQL stores the value in pg_shadow.

Install

$ npm install pg-password-util

Dependencies

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

import { genAlterUserPasswordSql } = require('pg-password-util');

const sql = genAlterUserPasswordSql({
    username: 'app',
    password: 'my-new-secret-password',
    passwordEncryption: 'scram-sha-256',
});

Generate encoded password for use in a custom CREATE USER statement

import { encodeScramSha256 } = require('pg-password-util');
import * as pgFormat from 'pg-format';

const encodedPassword = encodeScramSha256({
    password: 'my-new-secret-password',
    iterations: 10000,
});
const sql = pgFormat('CREATE USER app PASSWORD %L LOGIN', encodedPassword);

Change a user's password

import { alterUserPassword } = require('pg-password-util');

// client is a pg.Client
await alterUserPassword(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:

$ bin/postgres-server

Then, to run the tests run:

$ make test

License

ISC. See the file LICENSE.