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

dovehash

v0.0.5

Published

Library for working with Dovecot password hashes

Downloads

20

Readme

dovehash

Node.JS library for working with Dovecot password hashes

Written by Vladimir Neverov [email protected] in 2015

Homepage: https://github.com/vne/dovehash/wiki

Synopsis

Dovecot mail server uses its own special data format to store hashed passwords in databases. This is covered in details in Dovecot wiki. This library is intended to support this kind of password encoding in Node.JS applications, because it is convenient to have one common password storage format.

As for now, Dovehash works only with a subset of hashing schemes supported by Dovecot: PLAIN, CLEARTEXT, SHA, SHA1, SHA256, SHA512, SMD5, SSHA, SSHA256 and SSHA512. Pull requests are welcomed. Support for more hashing schemes is planned.

Simple MD5 is NOT supported due to weird calculation scheme used in Dovecot (see password_generate_md5_crypt function in Dovecot sources at src/auth/password-scheme-md5crypt.c for more).

Both base64 and hex encodings are supported, base64 is the default (as it is in Dovecot).

Library makes use of Node.JS Buffer class and can not be used in browser without some helper library (e.g., this one). This behavior is not tested yet.

Usage

First, you should require the library

var Dovehash = require('dovehash');

Then, if you have some hashed and, probably, salted password in Dovecot style (e.g. "{SSHA}PTggDCOUPEVj5h7bZjhxfKWQBpey47nF") and a plain password, supplied by user, (e.g. "abcdef") you can easily check them for equivalence:

var passwordsMatch = Dovehash.equal(hashedPassword, userSuppliedPassword);

If you have a plain password and want to encode it using one of the supported schemes:

var encoded = Dovehash.encode('SSHA', yourPlainPassword, salt);

If salt is not supplied, it is generated automatically. Dovehash.encode returns Dovehash instance that can be stringified to Dovecot-style hash via .toString or .inspect call.

Finally, you can create a Dovehash instance for hashed password:

var dh = new Dovehash(hashedPassword);
console.log(dh.toJSON());

This will parse hashed password and give you access to hashing algorithm, encoding, password hash and salt.

API

You can create a Dovehash instance for hashed password (constructor may throw exceptions):

var dh = new Dovehash(hashedPassword);

This instance will have the following methods:

  • equals(clearTextPassword) - calculate appropriate hash for clearTextPassword and compare with the hashed one. Returns either true or false.
  • toJSON() - get hash properties as JSON (currently: input, scheme, encoding, salt, password, where input is the original string and password is hex-encoded hash)
  • toString() - get Dovecot-style hash
  • inspect() - save as toString()

Dovehash also has several static methods:

  • Dovehash.equal(hashed, clearText) - compare clearText to hashed, catch exceptions and return false if anything is caught. Returns either true or false.
  • encode(scheme, clearText, salt) - encode clearText to scheme with salt. Returns Dovehash instance.
  • getSalt(hashed) - parse hashed password and return salt if there is any. Returns Buffer.

Errors

Dovehash constructor throws exceptions if something is wrong. Go catch them :)

Testing

Some examples of library usage can be found in test.js file. To run tests you will need Mocha, the tests themselves use built-in NodeJS assert module