Lib to help you hash passwords.
bcrypt on wikipedia
Catalyst: How To Safely Store A Password
- NodeJS
- BSD Libs (non-mac)
npm install bcrypt
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');
bcrypt.compare("B4c0//", hash); // true
bcrypt.compare("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 [email protected] nodeunit test/
The code for this comes from a few sources:
- blowfish.cc - OpenBSD
- bcrypt.cc - OpenBSD
- bcrypt::gen_salt - gen_salt inclusion to bcrypt
- bcrypt_node.cc - me
Unless stated elsewhere, file headers or otherwise, the license as stated in the LICENSE file.