node package manager
Stop wasting time. Easily manage code sharing in your team. Create a free org ยป



Lib to help you hash passwords.
bcrypt on wikipedia

Catalyst: How To Safely Store A Password


  • NodeJS
  • BSD Libs (non-mac)

From NPM

npm install bcrypt

From Source

I run K/Ubuntu. I was able to pull in the bsd libs using:
sudo apt-get install libbsd-dev
Eventually I'd like to get it so that the libs are all built in to the same package. But, as a work in progress, this gets the job done for now.

What is required is the file stdlib.h within /usr/includes/bsd/ and the compiled bsd libs in /usr/lib/. These have to match the conf.check.

Assuming you've already built node, you can run the waf script:
node-waf configure node-waf build npm link


To hash a password:
var bcrypt = require('bcrypt');
var salt = bcrypt.gen_salt(10);
var hash = bcrypt.hashpw("B4c0//", salt);

To check a password:
var bcrypt = require('bcrypt');"B4c0//", hash); // true"not_bacon", hash); // false


I am using nodeunit. I like the way you write tests with it and I like the default output. As such you'll need it to run the tests. I suspect my tests would run on an older version, but these were written and worked against 0.3.1 npm install nodeunit@0.3.1 nodeunit test/


The code for this comes from a few sources:


Antonio Salazar Cardozo


Unless stated elsewhere, file headers or otherwise, the license as stated in the LICENSE file.