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

hmax

v1.1.2

Published

secure password retention/verification based on salted HMAC hashes with configurable prefixes and character encodings

Downloads

7

Readme

HMax

a flexible library for secure password verification and retention based on salted HMAC hashes with configurable prefixes and character encodings

Getting Started

Install HMax:

npm install hmax --save

Overview

HMax can be used to generate or verify secure password hashes. You can specify the HMAC algorithm, number of iterations, salt value/character encoding, input prefix/encoding and output encoding. Of course the library provides intelligent defaults that are typically recommended, but the flexibility can be very useful when integrating or migrating from an external system. This library was heavily inspired by David Wood's password-hash npm module.

Examples

A password hash with default options:

var hmax = require('hmax');

// generate a password hash for the password 'Mellon'
var hash = hmax.generate('Mellon');
//-> {
//->   algorithm: 'sha1',
//->   iterations: 1,
//->   salt: { encoding: 'utf8', value: 'WCgN2E4g' },
//->   input: { prefix: '', encoding: 'utf8' },
//->   output: { encoding: 'hex', value: '4353f21329879b1768dcc2e35a137d0d605646fb' }
//-> }

// verify the password against the original hash
hmax.verify('Mellon', hash);
//-> true

// verify an invalid password against the original hash
hmax.verify('Mordor', hash);
//-> false

// encode the password hash for efficient transfer and storage
var encoded = hmax.encode(hash);
//-> 'sha1$WCgN2E4g$4353f21329879b1768dcc2e35a137d0d605646fb'

// decode the encoded password
var decoded = hmax.decode(encoded);
//-> {
//->   algorithm: 'sha1',
//->   iterations: 1,
//->   salt: { encoding: 'utf8', value: 'WCgN2E4g' },
//->   input: { prefix: '', encoding: 'utf8' },
//->   output: { encoding: 'hex', value: '4353f21329879b1768dcc2e35a137d0d605646fb' }
//-> }

// verify the password against the decoded hash
hmax.verify('Mellon', decoded);
//-> true

// verify an invalid password against the decoded hash
hmax.verify('Mordor', decoded);
//-> false

A password hash with fixed salt (yikes!), a custom input prefix/encoding and a custom output encoding:

var hmax = require('hmax');

// generate a password hash for the password 'Mellon'
var hash = hmax.generate('Mellon', {
  salt: { value: '36ae2f9afb', encoding: 'hex' },
  input: { prefix: 'Sindarin', encoding: 'utf16le' },
  output: { encoding: 'base64' }
});
//-> {
//->   algorithm: 'sha1',
//->   iterations: 1,
//->   salt: { encoding: 'hex', value: '36ae2f9afb' },
//->   input: { prefix: 'Sindarin', encoding: 'utf16le' },
//->   output: { encoding: 'base64', value: 'eIaOmtdv6eEP4iUhLw0egzBDAow=' }
//-> }

// verify the password against the original hash
hmax.verify('Mellon', hash);
//-> true

// verify an invalid password against the original hash
hmax.verify('Mordor', hash);
//-> false

// encode the password hash for efficient transfer and storage
var encoded = hmax.encode(hash);
//-> 'sha1|Sindarin|utf16le$36ae2f9afb|hex$eIaOmtdv6eEP4iUhLw0egzBDAow=|base64'

// decode the encoded password
var decoded = hmax.decode(encoded);
//-> {
//->   algorithm: 'sha1',
//->   iterations: 1,
//->   salt: { encoding: 'hex', value: '36ae2f9afb' },
//->   input: { prefix: 'Sindarin', encoding: 'utf16le' },
//->   output: { encoding: 'base64', value: 'eIaOmtdv6eEP4iUhLw0egzBDAow=' }
//-> }

// verify the password against the decoded hash
hmax.verify('Mellon', decoded);
//-> true

// verify an invalid password against the decoded hash
hmax.verify('Mordor', decoded);
//-> false

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Release History

(Nothing yet)