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

xkcd-z-password

v2.3.1

Published

XKCD-style password generator

Downloads

3

Readme

xkcd-z-password

An XKCD-style password generator.

By default, it comes with 113809 officially recognised words, of which only 70806 are in the default filter. For the same with no badwords, use @ZaneHannanAU/xkcd-z-password-nobadwords.

It is heavily based on @fardog/node-xkcd-password, however some aspects of generation are rather different.

Usage

const xkcdPassword = require('xkcd-z-password').init();

xkcdPassword.generate().then(a => console.log(a.join(' ')));
xkcdPassword.generate(7).then(a => a.join(' ')).then(console.log);

// ... in an asynchronous DB
xkcdPassword.generate(4)
.then(a => {
  let pw = a.join(' ');
  notifyUser({newPW: pw});
  return pw;
})
.then(DefaultPasswordHashingFunction)

Note that this is a single use, not indicative of all possible uses.

For example, here is one with longer and shorter passwords.

// A better use
const xkcdPassword = require('xkcd-z-password').init({
  minLength: 3, maxLength: 9, numWords: 3
});

// db data set given a user value or function
xkcdPassword.generate()
.then(pw => pw.join(' '))
.then(pw => {
  user.setPassword(pw) // recommended for pw storage: bcrypt/bcryptwasm/bcryptjs
  .then(b => {
    if (b) user.notify({type: 'PWSET', data: pw})
  })
})

Differences

xkcd-z-password runs off an integrated array where all indefinites are removed, allowing faster password generation (non-redoing) and possibly lower memory usage (fewer instances of uvstrings in memory).

On the flipside, it means that once it's "ready", it cannot be modified beyond the addition of words that match the generated or provided filter function.

The provided filter function does not include the mentioned bad words, being many times more simple in nature (comparing length).

CLI

A mini CLI is bundled with the package, providing some basic setup and functionality, as well as a simple test.

Note that it does not use anything specific, and is decidedly short and generic to allow it to be made easily, accessible via cd node_modules/xkcd-z-password && npm start.

The entirety of it is listed below.

const repl = require('repl');

require('.')
.init({minLength: 0, maxLength: Infinity, numWords: 4})
.once('ready', x => {
  console.log('Ready');
  const r = repl.start('> ');
  r.context.xkcdp = x;
  r.defineCommand('generate', {
    help: 'xkcd-z-password: generate and log password',
    action(length) {
      x.generate(parseInt(length || '4'))
      .then(generated => generated.join(' '))
      .then(console.log)
      .catch(console.error)
      .then(() => this.displayPrompt())
    }
  })
})