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

passworks

v0.3.0

Published

A generic password library.

Downloads

0

Readme

passworks - simple javascript password library

passworks provides a simple and versatile interface for managing password hashes.

  • Extensible strategy support.
  • Password validation.
  • Error handling.
  • Generate strings and objects with strategy meta data.
  • Loading from generated strings and objects.

The only included strategy is PBKDF2. You'll need to call Passworks.init() first to set that strategy, and other options.

API Usage

Passworks.init(options)

Set options for new instances. Must be called prior to any new instantiation.

Passworks.init({
	strategy: 'pbkdf2',
	algorithm: 'SHA512',
	iterations: 128000,
	keyLength: 32
});
Passworks.digest(secret[, returnHash])

Perform key derivation and digest of the string argument secret.

Sets the derived hash digest string to the instance. Returns a promise resolved and bound to this.

When the returnHash argument is true, resolves as the hash string without setting the hash property of the instance.

var pw = new Passworks();

// Derive and digest. Setting `this.hash` to the derived key.
ps.digest('somepassword') // Promise - passworks instance

// Derive, digest, and return a promise resolved with the hash.
ps.digest('anotherpassword')
	.tap(console.log); // 687e6e5bde7369d263d360e42aff51d1
Passworks.matches(secret)

Check if an instance hash matches the hash of the provided secret;

Returns a promise resolved and bound to this if the hash matches. Rejects with a Passworks.PasswordError otherwise.

var pw = new Passworks('mysecret');

pw.matches('mysecret')
	.then(function() {
		// Password is valid
	});

// Failure
pw.matches('badsecret')
	.catch(Passworks.PasswordError, function() {
		// Password is invalid
	});
Passworks.addStrategy(strategy, fn)

Add a password strategy function. PBKDF2 is currently the only provided strategy. The function should return the hash string, or a Promise if async.

Passworks.addStrategy('simple', function(secret) {
	return crypto.createHash(this.algorithm).update(secret).digest('hex');
});

Passworks.init({
	strategy: 'simple',
	keyLength: 16,
	algorithm: 'md5' }
);

var pw = new Passworks();

pw.digest('weaksecret')
	.call('toString')
	.tap(console.log); // simple:md5::16:b82d330d81b01168f963daeb94e3bfa9:b7dec8884bcff8bc682ded0292f3efe2
Passworks.toString()

Return a string containing the hash and other meta data in the format: strategy:algorithm:iterations:keyLength:salt:hash

pw.toString(); // pbkdf2:SHA512:1000:16:036b12783633b4684682d640ec2d8db9:101d7f1fe4fbe10305834c6cd03b2aa0
Passworks.fromString()

Create a passworks instance from a string.

Passworks.fromString('pbkdf2:SHA512:1000:16:036b12783633b4684682d640ec2d8db9:101d7f1fe4fbe10305834c6cd03b2aa0');
Passworks.toObject([keyLength])

Returns a simple object representation of the password hash and meta data:

{
	strategy: this.strategy,
	algorithm: this.algorithm,
	iterations: this.iterations,
	keyLength: this.keyLength,
	salt: this.salt,
	hash: this.hash
};
Passworks.fromObject([keyLength])

Creates and returns a passworks instance from an object.

var passwordObject = {
	strategy: 'pbkdf2',
	algorithm: 'SHA512'
	iterations: 128000,
	keyLength: 64,
	salt: '036b12783633b4684682d640ec2d8db9',
	hash: '101d7f1fe4fbe10305834c6cd03b2aa0'
}

var pw = Passworks.fromObject(passwordObject);
Passworks.genSalt([keyLength])

Called by default on instantiation. Returns a hex string using options.keyLength byte length when an instance, keyLength argument statically.

Uses crypto.randomBytes().

var salt = Passworks.genSalt(16); // e1292b9291ef5c2edfa1735f3e348b8c