Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bcrypt

Package Overview
Dependencies
Maintainers
5
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 1.1.0-napi to 2.0.0

.editorconfig

28

bcrypt.js

@@ -15,3 +15,3 @@ 'use strict';

/// @return {String} salt
module.exports.genSaltSync = function genSaltSync(rounds) {
module.exports.genSaltSync = function genSaltSync(rounds, minor) {
// default 10 rounds

@@ -24,3 +24,10 @@ if (!rounds) {

return bindings.gen_salt_sync(rounds, crypto.randomBytes(16));
if(!minor) {
minor = 'b';
} else if(minor !== 'b' && minor !== 'a') {
console.log(minor, typeof minor);
throw new Error('minor must be either "a" or "b"');
}
return bindings.gen_salt_sync(minor, rounds, crypto.randomBytes(16));
};

@@ -31,3 +38,3 @@

/// @param {Function} cb callback(err, salt)
module.exports.genSalt = function genSalt(rounds, ignore, cb) {
module.exports.genSalt = function genSalt(rounds, minor, cb) {
var error;

@@ -40,2 +47,3 @@

rounds = 10;
minor = 'b';
// callback is second argument

@@ -45,6 +53,7 @@ } else if (typeof arguments[1] === 'function') {

cb = arguments[1];
minor = 'b';
}
if (!cb) {
return promises.promise(genSalt, this, [rounds, ignore]);
return promises.promise(genSalt, this, [rounds, minor]);
}

@@ -63,2 +72,11 @@

if(!minor) {
minor = 'b'
} else if(minor !== 'b' && minor !== 'a') {
error = new Error('minor must be either "a" or "b"');
return process.nextTick(function() {
cb(error);
});
}
crypto.randomBytes(16, function(error, randomBytes) {

@@ -70,3 +88,3 @@ if (error) {

bindings.gen_salt(rounds, randomBytes, cb);
bindings.gen_salt(minor, rounds, randomBytes, cb);
});

@@ -73,0 +91,0 @@ };

9

CHANGELOG.md

@@ -1,10 +0,5 @@

# 1.1.0-napi (2018-01-21)
# 2.0.0 (2018-04-07)
* Initial support for [N-API](https://nodejs.org/api/n-api.html)
* Make `2b` the default bcrypt version
# 1.0.3 (2016-08-23)
* update to nan v2.6.2 for NodeJS 8 support
* Fix: use npm scripts instead of node-gyp directly.
# 1.0.2 (2016-12-31)

@@ -11,0 +6,0 @@

'use strict';
var Promise = global.Promise;
/// encapsulate a method with a node-style callback in a Promise

@@ -7,3 +9,3 @@ /// @param {object} 'this' of the encapsulated function

/// @param {Array-like} args to be passed to the called function
/// @return {Promise} a Promise encapuslaing the function
/// @return {Promise} a Promise encapsulating the function
module.exports.promise = function (fn, context, args) {

@@ -36,1 +38,7 @@

};
/// changes the promise implementation that bcrypt uses
/// @param {Promise} the implementation to use
module.exports.use = function(promise) {
Promise = promise;
};

@@ -14,3 +14,3 @@ {

"main": "./bcrypt",
"version": "1.1.0-napi",
"version": "2.0.0",
"author": "Nick Campbell (https://github.com/ncb000gt)",

@@ -33,8 +33,7 @@ "engines": {

"dependencies": {
"bindings": "1.3.0",
"node-addon-api": "1.1.0",
"node-pre-gyp": "0.6.39"
"nan": "2.10.0",
"node-pre-gyp": "0.9.0"
},
"devDependencies": {
"nodeunit": "~0.9.1"
"nodeunit": "~0.11.1"
},

@@ -56,4 +55,3 @@ "contributors": [

"Fanie Oosthuysen <fanie.oosthuysen@gmail.com> (https://github.com/weareu)",
"Amitosh Swain Mahapatra <amitosh.swain@gmail.com> (https://github.com/Agathver)",
"Nicola Del Gobbo <nicoladelgobbo@gmail.com> (https://github.com/NickNaso)"
"Amitosh Swain Mahapatra <amitosh.swain@gmail.com> (https://github.com/Agathver)"
],

@@ -64,4 +62,5 @@ "binary": {

"host": "https://github.com",
"remote_path": "/kelektiv/node.bcrypt.js/releases/download/v{version}/"
"remote_path": "/kelektiv/node.bcrypt.js/releases/download/v{version}/",
"package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}-{libc}.tar.gz"
}
}

@@ -45,2 +45,8 @@ # node.bcrypt.js

## Compatibility Note
This library supports `$2a$` and `$2b$` prefix bcrypt hashes. `$2x$` and `$2y$` hashes are specific to bcrypt implementation developed for Jon the Ripper. In theory, they should be compatible with `$2b$` prefix.
Compatibility with hashes generated by other languages is not 100% guaranteed due to difference in character encodings. However, it should not be an issue for most cases.
## Dependencies

@@ -179,6 +185,8 @@

* `genSaltSync(rounds)`
* `genSaltSync(rounds, minor)`
* `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10)
* `genSalt(rounds, cb)`
* `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b)
* `genSalt(rounds, minor, cb)`
* `rounds` - [OPTIONAL] - the cost of processing the data. (default - 10)
* `minor` - [OPTIONAL] - minor version of bcrypt to use. (default - b)
* `cb` - [OPTIONAL] - a callback to be fired once the salt has been generated. uses eio making it asynchronous. If `cb` is not specified, a `Promise` is returned if Promise support is available.

@@ -266,4 +274,3 @@ * `err` - First parameter to the callback detailing any errors.

* [Fanie Oosthuysen][weareu] - Windows Support
* [Amitosh Swain Mahapatra][agathver] - ES6 Promise Support
* [Nicola Del Gobbo][NickNaso] - Initial implementation with N-API
* [Amitosh Swain Mahapatra][agathver] - $2b$ hash support, ES6 Promise support

@@ -296,2 +303,1 @@ ## License

[agathver]:https://github.com/Agathver
[NickNaso]: https://github.com/NickNaso

@@ -22,3 +22,3 @@ var bcrypt = require('../bcrypt');

test_salt_rounds_is_string_non_number: function(assert) {
bcrypt.genSalt('b', function (err, salt) {
bcrypt.genSalt('z', function (err, salt) {
assert.ok((err instanceof Error), "Should throw an Error. genSalt requires rounds to of type number.");

@@ -28,2 +28,22 @@ assert.done();

},
test_salt_minor: function(assert) {
assert.expect(3);
bcrypt.genSalt(10, 'a', function(err, salt) {
assert.strictEqual(29, salt.length, "Salt isn't the correct length.");
var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[2], '10');
assert.done();
});
},
test_salt_minor_b: function(assert) {
assert.expect(3);
bcrypt.genSalt(10, 'b', function(err, salt) {
assert.strictEqual(29, salt.length, "Salt isn't the correct length.");
var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');
assert.done();
});
},
test_hash: function(assert) {

@@ -89,3 +109,3 @@ assert.expect(1);

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');

@@ -99,3 +119,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '04');

@@ -109,3 +129,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '31');

@@ -112,0 +132,0 @@ assert.done();

@@ -14,2 +14,7 @@ var bcrypt = require('../bcrypt');

},
openbsd_bcrypt_tests: function(assert) {
assert.strictEqual(bcrypt.hashSync("000000000000000000000000000000000000000000000000000000000000000000000000", "$2a$05$CCCCCCCCCCCCCCCCCCCCC."), "$2a$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS");
assert.strictEqual(bcrypt.hashSync("000000000000000000000000000000000000000000000000000000000000000000000000", "$2b$05$CCCCCCCCCCCCCCCCCCCCC."), "$2b$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS");
assert.done();
},
test_long_passwords: function(assert) {

@@ -19,2 +24,6 @@ // bcrypt wrap-around bug in $2a$

assert.strictEqual(bcrypt.hashSync("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", "$2a$05$CCCCCCCCCCCCCCCCCCCCC."), "$2a$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS");
// tests for $2b$ which fixes wrap-around bugs
assert.strictEqual(bcrypt.hashSync("012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234", "$2b$05$CCCCCCCCCCCCCCCCCCCCC."), "$2b$05$CCCCCCCCCCCCCCCCCCCCC.XxrQqgBi/5Sxuq9soXzDtjIZ7w5pMfK");
assert.strictEqual(bcrypt.hashSync("0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345", "$2b$05$CCCCCCCCCCCCCCCCCCCCC."), "$2b$05$CCCCCCCCCCCCCCCCCCCCC.6.O1dLNbjod2uo0DVcW.jHucKbPDdHS");
assert.done();

@@ -28,3 +37,10 @@ },

assert.done();
},
test_consistency: function(assert) {
assert.strictEqual(bcrypt.hashSync("ππππππππ", "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeu"), "$2a$10$.TtQJ4Jr6isd4Hp.mVfZeuh6Gws4rOQ/vdBczhDx.19NFK0Y84Dle");
assert.strictEqual(bcrypt.hashSync("p@5sw0rd", "$2b$12$zQ4CooEXdGqcwi0PHsgc8e"), "$2b$12$zQ4CooEXdGqcwi0PHsgc8eAf0DLXE/XHoBE8kCSGQ97rXwuClaPam");
assert.strictEqual(bcrypt.hashSync("C'est bon, la vie!", "$2b$12$cbo7LZ.wxgW4yxAA5Vqlv."), "$2b$12$cbo7LZ.wxgW4yxAA5Vqlv.KR6QFPt4qCdc9RYJNXxa/rbUOp.1sw.");
assert.strictEqual(bcrypt.hashSync("ἓν οἶδα ὅτι οὐδὲν οἶδα", "$2b$12$LeHKWR2bmrazi/6P22Jpau"), "$2b$12$LeHKWR2bmrazi/6P22JpauX5my/eKwwKpWqL7L5iEByBnxNc76FRW");
assert.done();
}
}
}
var bcrypt = require('../bcrypt');
var promises = require('../lib/promises');

@@ -127,3 +128,3 @@ var fail = function(assert, error) {

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');

@@ -137,3 +138,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '04');

@@ -147,3 +148,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '31');

@@ -221,4 +222,35 @@ assert.done();

});
},
test_change_promise_impl_reject: function(assert) {
promises.use({
reject: function() {
return 'mock';
}
});
assert.equal(promises.reject(), 'mock');
// need to reset the promise implementation because of require cache
promises.use(global.Promise);
assert.done();
},
test_change_promise_impl_promise: function(assert) {
promises.use({
reject: function(err) {
assert.equal(err.message, 'fn must be a function');
return 'mock';
}
});
assert.equal(promises.promise('', '', ''), 'mock');
// need to reset the promise implementation because of require cache
promises.use(global.Promise);
assert.done();
}
};
}

@@ -8,3 +8,3 @@ var bcrypt = require('../bcrypt');

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');

@@ -17,3 +17,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');

@@ -30,2 +30,18 @@ assert.done();

},
test_salt_minor_a: function(assert) {
var salt = bcrypt.genSaltSync(10, 'a');
assert.strictEqual(29, salt.length, "Salt isn't the correct length.");
var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[2], '10');
assert.done();
},
test_salt_minor_b: function(assert) {
var salt = bcrypt.genSaltSync(10, 'b');
assert.strictEqual(29, salt.length, "Salt isn't the correct length.");
var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');
assert.done();
},
test_hash: function(assert) {

@@ -61,3 +77,3 @@ assert.ok(bcrypt.hashSync('password', bcrypt.genSaltSync(10)), "Shouldn't throw an Error.");

assert.ok(bcrypt.hashSync('password', '$2a$10$somesaltyvaluertsetrse'));
assert.throws(function() {
assert.throws(function() {
bcrypt.hashSync('password', 'some$value');

@@ -70,3 +86,3 @@ });

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '10');

@@ -78,3 +94,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '04');

@@ -86,3 +102,3 @@ assert.done();

var split_salt = salt.split('$');
assert.strictEqual(split_salt[1], '2a');
assert.strictEqual(split_salt[1], '2b');
assert.strictEqual(split_salt[2], '31');

@@ -89,0 +105,0 @@ assert.done();

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