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

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.6.0 to 0.7.0

25

bcrypt.js

@@ -1,7 +0,2 @@

try {
var bindings = require('./build/default/bcrypt_lib');
} catch(e) {
//update for v0.5.5+
var bindings = require('./build/Release/bcrypt_lib');
}
var bindings = require('bindings')('bcrypt_lib');

@@ -94,6 +89,10 @@ /// generate a salt (sync)

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');
} else if (typeof data !== 'string' && (typeof salt !== 'string' || typeof salt !== 'number')) {
throw new Error('data must be a string and salt must either be a salt string or a number of rounds');
}
if (typeof salt === 'number') {
salt = module.exports.genSaltSync(salt);
}
return bindings.encrypt_sync(data, salt);

@@ -115,4 +114,4 @@ };

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');
} else if (typeof data !== 'string' && (typeof salt !== 'string' || typeof salt !== 'number')) {
throw new Error('data must be a string and salt must either be a salt string or a number of rounds');
}

@@ -126,2 +125,8 @@

if (typeof salt === 'number') {
return module.exports.genSalt(salt, function(err, salt) {
return bindings.encrypt(data, salt, cb);
});
}
return bindings.encrypt(data, salt, cb);

@@ -128,0 +133,0 @@ };

6

examples/async_compare.js
var bcrypt = require('../bcrypt');
var start = Date.now();
bcrypt.gen_salt(10, function(err, salt) {
bcrypt.genSalt(10, function(err, salt) {
console.log('salt: ' + salt);
console.log('salt cb end: ' + (Date.now() - start) + 'ms');
bcrypt.encrypt('test', salt, function(err, crypted) {
bcrypt.hash('test', salt, function(err, crypted) {
console.log('crypted: ' + crypted);
console.log('crypted cb end: ' + (Date.now() - start) + 'ms');
console.log('rounds used from hash:', bcrypt.get_rounds(crypted));
console.log('rounds used from hash:', bcrypt.getRounds(crypted));
bcrypt.compare('test', crypted, function(err, res) {

@@ -12,0 +12,0 @@ console.log('compared true: ' + res);

var bcrypt = require('../bcrypt');
while (true) {
bcrypt.gen_salt(10, function(err, salt) {
(function printSalt() {
bcrypt.genSalt(10, function(err, salt) {
console.log('salt: ' + salt);
printSalt();
});
}
})()

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

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

@@ -25,2 +25,5 @@ "engines": { "node": ">= 0.6.0" },

},
"dependencies": {
"bindings": "1.0.0"
},
"devDependencies": {

@@ -27,0 +30,0 @@ "nodeunit": ">=0.6.4"

@@ -77,2 +77,6 @@ node.bcrypt.js

Auto-gen a salt and hash:
var hash = bcrypt.hashSync('bacon', 8)
Usage - Async

@@ -100,2 +104,7 @@ ============

Auto-gen a salt and hash:
bcrypt.hash('bacon', 8, function(err, hash) {
});
API

@@ -120,3 +129,3 @@ ============

* `data` - [REQUIRED] - the data to be encrypted.
* `salt` - [REQUIRED] - the salt to be used in encryption.
* `salt` - [REQUIRED] - the salt to be used to hash the password. if specified as a number then a salt will be generated and used (see examples).
* `cb` - [REQUIRED] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous.

@@ -123,0 +132,0 @@ * `err` - First parameter to the callback detailing any errors.

@@ -36,2 +36,9 @@ var bcrypt = require('../bcrypt');

},
test_hash_rounds: function(assert) {
assert.expect(1);
bcrypt.hash('bacon', 8, function(err, hash) {
assert.equals(bcrypt.getRounds(hash), 8, "Number of rounds should be that specified in the function call.");
assert.done();
});
},
test_hash_empty_strings: function(assert) {

@@ -38,0 +45,0 @@ assert.expect(2);

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

},
test_hash_rounds: function(assert) {
var hash = bcrypt.hashSync('password', 8);
assert.equals(bcrypt.getRounds(hash), 8, "Number of rounds should equal 8.");
assert.done();
},
test_hash_empty_string: function(assert) {

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

test_hash_pw_not_hash_str: function(assert) {
assert.throws(function() {bcrypt.hashSync('password', 1);}, "Should throw an Error. hash should be a string.");
assert.throws(function() {bcrypt.hashSync('password', {});}, "Should throw an Error. hash should be a string or number.");
assert.done();

@@ -51,0 +56,0 @@ },

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