Socket
Socket
Sign inDemoInstall

bcrypt

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bcrypt - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

examples/forever_gen_salt.js

148

bcrypt.js
try {
module.exports = require('./build/default/bcrypt_lib');
var bindings = require('./build/default/bcrypt_lib');
} catch(e) {
//update for v0.5.5+
module.exports = require('./build/Release/bcrypt_lib');
var bindings = require('./build/Release/bcrypt_lib');
}
/// generate a salt (sync)
/// @param {Number} [rounds] number of rounds (default 10)
/// @param {Number} [seed_length] number of random bytes (default 20)
/// @return {String} salt
module.exports.gen_salt_sync = function(rounds, seed_length) {
// default 10 rounds
if (!rounds) {
rounds = 10;
} else if (typeof rounds !== 'number') {
throw new Error('rounds must be a number');
}
// default length 20
if (!seed_length) {
seed_length = 20;
} else if (typeof seed_length !== 'number') {
throw new Error('seed_length must be a number');
}
return bindings.gen_salt_sync(rounds, seed_length);
};
/// generate a salt
/// @param {Number} [rounds] number of rounds (default 10)
/// @param {Number} [seed_length] number of random bytes (default 20)
/// @param {Function} cb callback(err, salt)
module.exports.gen_salt = function(rounds, seed_length, cb) {
// if callback is first argument, then use defaults for others
if (typeof arguments[0] === 'function') {
// have to set callback first otherwise arguments are overriden
cb = arguments[0];
rounds = 10;
seed_length = 20;
// callback is second argument
} else if (typeof arguments[1] === 'function') {
// have to set callback first otherwise arguments are overriden
cb = arguments[1];
seed_length = 20;
}
// default 10 rounds
if (!rounds) {
rounds = 10;
} else if (typeof rounds !== 'number') {
throw new Error('rounds must be a number');
}
// default length 20
if (!seed_length) {
seed_length = 20;
} else if (typeof seed_length !== 'number') {
throw new Error('seed_length must be a number');
}
if (!cb) {
throw new Error('callback required for gen_salt');
}
return bindings.gen_salt(rounds, seed_length, cb);
};
/// hash data using a salt
/// @param {String} data the data to encrypt
/// @param {String} salt the salt to use when hashing
/// @return {String} hash
module.exports.encrypt_sync = function(data, salt) {
if (!data || !salt) {
throw new Error('data and salt arguments required');
} else if (typeof data !== 'string' || typeof salt !== 'string') {
throw new Error('data and salt must be strings');
}
return bindings.encrypt_sync(data, salt);
};
/// hash data using a salt
/// @param {String} data the data to encrypt
/// @param {String} salt the salt to use when hashing
/// @param {Function} cb callback(err, hash)
module.exports.encrypt = function(data, salt, cb) {
if (!data || !salt) {
throw new Error('data and salt arguments required');
} else if (typeof data !== 'string' || typeof salt !== 'string') {
throw new Error('data and salt must be strings');
}
if (!cb) {
throw new Error('callback required for async compare');
} else if (typeof cb !== 'function') {
throw new Error('callback must be a function');
}
return bindings.encrypt(data, salt, cb);
};
/// compare raw data to hash
/// @param {String} data the data to hash and compare
/// @param {String} hash expected hash
/// @return {bool} true if hashed data matches hash
module.exports.compare_sync = function(data, hash) {
if (!data || !hash) {
throw new Error('data and hash arguments required');
} else if (typeof data !== 'string' || typeof hash !== 'string') {
throw new Error('data and hash must be strings');
}
return bindings.compare_sync(data, hash);
};
/// compare raw data to hash
/// @param {String} data the data to hash and compare
/// @param {String} hash expected hash
/// @param {Function} cb callback(err, matched) - matched is true if hashed data matches hash
module.exports.compare = function(data, hash, cb) {
if (!data || !hash) {
throw new Error('data and hash arguments required');
} else if (typeof data !== 'string' || typeof hash !== 'string') {
throw new Error('data and hash must be strings');
}
if (!cb) {
throw new Error('callback required for async compare');
} else if (typeof cb !== 'function') {
throw new Error('callback must be a function');
}
return bindings.compare(data, hash, cb);
};
/// @param {String} hash extract rounds from this hash
/// @return {Number} the number of rounds used to encrypt a given hash
module.exports.get_rounds = function(hash) {
if (!hash) {
throw new Error('hash argument required');
} else if (typeof hash !== 'string') {
throw new Error('hash must be a string');
}
return bindings.get_rounds(hash);
};

7

package.json

@@ -6,3 +6,3 @@ {

"main": "./bcrypt",
"version": "0.4.0",
"version": "0.4.1",
"author": "Nick Campbell (http://github.com/ncb000gt)",

@@ -20,3 +20,3 @@ "engines": { "node": ">= 0.4.0" },

"bugs": {
"web" : "http://github.com/ncb000gt/node.bcrypt.js/issues"
"url" : "http://github.com/ncb000gt/node.bcrypt.js/issues"
},

@@ -40,4 +40,5 @@ "scripts": {

"Roman Shtylman <shtylman@gmail.com> (https://github.com/shtylman)",
"Vadim Graboys <dimva13@gmail.com> (https://github.com/vadimg)"
"Vadim Graboys <dimva13@gmail.com> (https://github.com/vadimg)",
"Ben Noorduis <> (https://github.com/bnoordhuis)"
]
}

@@ -148,4 +148,5 @@ node.bcrypt.js

* [Lloyd Hilaiel][lloyd] - Documentation fixes
* [Roman Shtylman][shtylman] - Code refactoring and general rot reduction
* [Roman Shtylman][shtylman] - Code refactoring, general rot reduction, compile options, and better memory management with delete and new.
* [Vadim Graboys][vadimg] - Code changes to support 0.5.5+
* [Ben Noordhuis][bnoordhuis] - Fixed a thread safety issue in nodejs that was perfectly mappable to this module.

@@ -152,0 +153,0 @@ License

@@ -11,3 +11,7 @@ var testCase = require('nodeunit').testCase,

test_salt_no_params: function(assert) {
assert.throws(function() {bcrypt.gen_salt_sync();}, "Should not throw an Error. .");
// same as test_verify_salt except using default rounds of 10
var salt = bcrypt.gen_salt_sync();
var split_salt = salt.split('$');
assert.ok(split_salt[1], '2a');
assert.ok(split_salt[2], '10');
assert.done();

@@ -14,0 +18,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc