Skip to content

Instantly share code, notes, and snippets.

@willricketts
Created January 27, 2015 19:01
Show Gist options
  • Save willricketts/8880d880341d0d95862c to your computer and use it in GitHub Desktop.
Save willricketts/8880d880341d0d95862c to your computer and use it in GitHub Desktop.
Super simple Node.js password hashing and checking
var bcrypt = require('bcrypt');
module.exports = {
hashPassword: hashPassword,
checkPassword: checkPassword
};
function hashPassword(password, callback) {
bcrypt.genSalt(10, function(err, salt) {
bcrypt.hash(password, salt, function(err, hash) {
callback(err, hash);
});
});
}
function checkPassword(password, callback) {
bcrypt.compare(password, hash, function(err, passwordsMatch) {
passwordsMatch = (err) ? err : passwordsMatch;
callback(err, passwordsMatch);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment