Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
bcrypt for NodeJs
C++ JavaScript C Other

This branch is 251 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
src
test
.gitignore
LICENSE
README.md
bcrypt.js
package.json
wscript

README.md

bcrypt-node

Lib to help you hash passwords.
bcrypt on wikipedia

Catalyst: How To Safely Store A Password

Dependencies

  • NodeJS
  • OpenSSL

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

Usage - Sync

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

To check a password:
var bcrypt = require('bcrypt');
var salt = bcrypt.gen_salt_sync(10);
var hash = bcrypt.encrypt_sync("B4c0/\/", salt); bcrypt.compare_sync("B4c0/\/", hash); // true
bcrypt.compare_sync("not_bacon", hash); // false

Usage - Async

To hash a password:
var bcrypt = require('bcrypt');
bcrypt.gen_salt(10, function(err, salt) { bcrypt.encrypt("B4c0/\/", salt, function(err, hash) { //something }); });

To check a password:
var bcrypt = require('bcrypt'); bcrypt.gen_salt(10, function(err, salt) { bcrypt.encrypt("B4c0/\/", salt, function(err, hash) { bcrypt.compare("B4c0/\/", hash, function(err, res) { // res == true
}); bcrypt.compare("not_bacon", hash, function(err, res) { // res = false }); }); });

Hash Info

The characters that comprise passwords are ./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789$.

Testing

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.5.1 npm install nodeunit@0.5.1 nodeunit test/

Credits

The code for this comes from a few sources:

Contributors

Antonio Salazar Cardozo

License

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

Something went wrong with that request. Please try again.