Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

bcrypt

Package Overview
Dependencies
Maintainers
1
Versions
55
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.2.4
to
0.3.0
+22
Makefile
TESTS = test/*.js
all: test
build: clean configure compile
configure:
node-waf configure
compile:
node-waf build
test: build
@./node_modules/nodeunit/bin/nodeunit \
$(TESTS)
clean:
rm -f bcrypt_lib.node
rm -Rf build
.PHONY: clean test build
+6
-3

@@ -1,3 +0,6 @@

var bcrypt_lib = require('./bcrypt_lib');
module.exports = new bcrypt_lib.BCrypt();
try {
module.exports = require('./build/default/bcrypt_lib');
} catch(e) {
//update for v0.5.5+
module.exports = require('./build/Release/bcrypt_lib');
}
{
"name": "bcrypt",
"description": "A bcrypt library for NodeJS.",
"keywords": ["bcrypt","password","auth","authentication","encryption","crypt","crypto"],
"main": "./bcrypt",
"version": "0.2.4",
"version": "0.3.0",
"author": "Nick Campbell (http://github.com/ncb000gt)",
"engines": { "node": ">= 0.1.100" },
"engines": { "node": ">= 0.4.0" },
"repository": {

@@ -21,7 +22,7 @@ "type": "git",

"scripts": {
"install": "node-waf configure build",
"test": "node-waf configure build; nodeunit test/"
"install": "make build",
"test": "make test"
},
"devDependencies": {
"nodeunit": ">=0.5.1"
"nodeunit": ">=0.5.4"
},

@@ -35,4 +36,7 @@ "contributors": [

"Alfred Westerveld <alfredwesterveld@gmail.com> (https://github.com/alfredwesterveld)",
"Vincent Côté-Roy <vincentcr@gmail.com> (https://github.com/vincentcr)"
"Vincent Côté-Roy <vincentcr@gmail.com> (https://github.com/vincentcr)",
"Lloyd Hilaiel <lloyd@hilaiel.com> (https://github.com/lloyd)",
"Roman Shtylman <shtylman@gmail.com> (https://github.com/shtylman)",
"Vadim Graboys <dimva13@gmail.com> (https://github.com/vadimg)"
]
}
+38
-31

@@ -1,8 +0,8 @@

bcrypt-node
node.bcrypt.js
=============
Lib to help you hash passwords.
Lib to help you hash passwords.
[bcrypt on wikipedia][bcryptwiki]
Catalyst: [How To Safely Store A Password][codahale]
Catalyst for this module: [How To Safely Store A Password][codahale]

@@ -17,3 +17,2 @@

* [GH-13][gh13] - There was a timing attack present in the comparator. This is fixed in versions higher than 0.2.1, but I recommend using 0.2.3 (code fixes) or later. HT [thegoleffect][thegoleffect].
* An [issue with passwords][jtr] was found with a version of the Blowfish algorithm developed for John the Ripper. This is not present in the OpenBSD version and is thus not a problem for this module. HT [zooko][zooko].

@@ -88,25 +87,32 @@

* BCrypt
* gen_salt_sync(rounds, seed_length)
* rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
* seed_length - [OPTIONAL] - RAND_bytes wants a length. to make that a bit flexible, you can specify a seed_length. (default - 20)
* gen_salt(rounds, seed_length, cb)
* rounds - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
* seed_length - [OPTIONAL] - RAND_bytes wants a length. to make that a bit flexible, you can specify a seed_length. (default - 20)
* cb - [REQUIRED] - a callback to be fired once the salt has been generated. uses eio making it asynchronous.
* encrypt_sync(data, salt)
* data - [REQUIRED] - the data to be encrypted.
* salt - [REQUIRED] - the salt to be used in encryption.
* encrypt(data, salt, cb)
* data - [REQUIRED] - the data to be encrypted.
* salt - [REQUIRED] - the salt to be used in encryption.
* cb - [REQUIRED] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous.
* compare_sync(data, encrypted)
* data - [REQUIRED] - data to compare.
* encrypted - [REQUIRED] - data to be compared to.
* compare(data, encrypted, cb)
* data - [REQUIRED] - data to compare.
* encrypted - [REQUIRED] - data to be compared to.
* cb - [REQUIRED] - a callback to be fired once the data has been compared. uses eio making it asynchronous.
`BCrypt.`
* `gen_salt_sync(rounds, seed_length)`
* `rounds` - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
* `seed_length` - [OPTIONAL] - RAND_bytes wants a length. to make that a bit flexible, you can specify a seed_length. (default - 20)
* `gen_salt(rounds, seed_length, cb)`
* `rounds` - [OPTIONAL] - the number of rounds to process the data for. (default - 10)
* `seed_length` - [OPTIONAL] - RAND_bytes wants a length. to make that a bit flexible, you can specify a seed_length. (default - 20)
* `cb` - [REQUIRED] - a callback to be fired once the salt has been generated. uses eio making it asynchronous.
* `err` - First parameter to the callback detailing any errors.
* `salt` - Second parameter to the callback providing the generated salt.
* `encrypt_sync(data, salt)`
* `data` - [REQUIRED] - the data to be encrypted.
* `salt` - [REQUIRED] - the salt to be used in encryption.
* `encrypt(data, salt, cb)`
* `data` - [REQUIRED] - the data to be encrypted.
* `salt` - [REQUIRED] - the salt to be used in encryption.
* `cb` - [REQUIRED] - a callback to be fired once the data has been encrypted. uses eio making it asynchronous.
* `err` - First parameter to the callback detailing any errors.
* `encrypted` - Second parameter to the callback providing the encrypted form.
* `compare_sync(data, encrypted)`
* `data` - [REQUIRED] - data to compare.
* `encrypted` - [REQUIRED] - data to be compared to.
* `compare(data, encrypted, cb)`
* `data` - [REQUIRED] - data to compare.
* `encrypted` - [REQUIRED] - data to be compared to.
* `cb` - [REQUIRED] - a callback to be fired once the data has been compared. uses eio making it asynchronous.
* `err` - First parameter to the callback detailing any errors.
* `same` - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
Hash Info

@@ -145,2 +151,5 @@ ============

* [Vincent Côté-Roy][vincentr] - Testing around concurrency issues
* [Lloyd Hilaiel][lloyd] - Documentation fixes
* [Roman Shtylman][shtylman] - Code refactoring and general rot reduction
* [Vadim Graboys][vadimg] - Code changes to support 0.5.5+

@@ -152,9 +161,4 @@ License

Trademarks?
============
Node.js™ is an official trademark of Joyent. This module is not formally related to or endorsed by the official Joyent Node.js open source or commercial project
[bcryptwiki]: http://en.wikipedia.org/wiki/Crypt_(Unix)#Blowfish-based_scheme

@@ -174,1 +178,4 @@ [bcryptgs]: http://mail-index.netbsd.org/tech-crypto/2002/05/24/msg000204.html

[vincentr]:https://twitter.com/vincentcr
[lloyd]:https://github.com/lloyd
[shtylman]:https://github.com/shtylman
[vadimg]:https://github.com/vadimg

@@ -32,3 +32,3 @@ /*

#include <node.h>
#include <node_events.h>
#include <node_version.h>
#include <ctype.h>

@@ -42,34 +42,35 @@ #include <string.h>

#include "node_blf.h"
#include "bcrypt_node.h"
#define NODE_LESS_THAN (!(NODE_VERSION_AT_LEAST(0, 5, 0)))
using namespace v8;
using namespace node;
namespace {
void BCrypt::Initialize (Handle<Object> target) {
HandleScope scope;
struct base_request {
v8::Persistent<v8::Function> callback;
const char *error;
};
Local<FunctionTemplate> t = FunctionTemplate::New(New);
struct salt_request : base_request {
char *salt;
int salt_len;
int rand_len;
ssize_t rounds;
};
t->InstanceTemplate()->SetInternalFieldCount(1);
struct encrypt_request : base_request {
char *salt;
char *input;
char *output;
int output_len;
};
NODE_SET_PROTOTYPE_METHOD(t, "gen_salt_sync", BCrypt::GenerateSaltSync);
NODE_SET_PROTOTYPE_METHOD(t, "encrypt_sync", BCrypt::EncryptSync);
NODE_SET_PROTOTYPE_METHOD(t, "compare_sync", BCrypt::CompareSync);
NODE_SET_PROTOTYPE_METHOD(t, "gen_salt", BCrypt::GenerateSalt);
NODE_SET_PROTOTYPE_METHOD(t, "encrypt", BCrypt::Encrypt);
NODE_SET_PROTOTYPE_METHOD(t, "compare", BCrypt::Compare);
struct compare_request : base_request {
char *input;
char *encrypted;
bool result;
};
target->Set(String::NewSymbol("BCrypt"), t->GetFunction());
}
Handle<Value> BCrypt::New(const Arguments& args) {
HandleScope scope;
BCrypt *bcrypt = new BCrypt();
bcrypt->Wrap(args.This());
return args.This();
}
int GetSeed(u_int8_t *seed, int size) {

@@ -129,5 +130,8 @@ switch (RAND_bytes((unsigned char *)seed, size)) {

/* SALT GENERATION */
int BCrypt::EIO_GenSalt(eio_req *req) {
#if NODE_LESS_THAN
int EIO_GenSalt(eio_req *req) {
#else
void EIO_GenSalt(eio_req *req) {
#endif
salt_request *s_req = (salt_request *)req->data;
BCrypt *bcrypt_obj = (BCrypt *)s_req->bcrypt_obj;

@@ -149,12 +153,11 @@ char *salt = (char *)malloc(_SALT_LEN);

} catch (const char *err) {
int err_len = strlen(err);
s_req->error = (char *)malloc(err_len * sizeof(err));
memcpy(s_req->error, err, err_len * sizeof(err));
s_req->error = err;
free(salt);
}
#if NODE_LESS_THAN
return 0;
#endif
}
int BCrypt::EIO_GenSaltAfter(eio_req *req) {
int EIO_GenSaltAfter(eio_req *req) {
HandleScope scope;

@@ -185,5 +188,3 @@

free(s_req->salt);
free(s_req->error);
((BCrypt *)s_req->bcrypt_obj)->Unref();
free(s_req);

@@ -194,4 +195,3 @@

Handle<Value> BCrypt::GenerateSalt(const Arguments &args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> GenerateSalt(const Arguments &args) {
HandleScope scope;

@@ -230,6 +230,5 @@

if (!s_req)
return ThrowException(Exception::Error(String::New("malloc in BCrypt::GenerateSalt failed.")));
return ThrowException(Exception::Error(String::New("malloc in GenerateSalt failed.")));
s_req->callback = Persistent<Function>::New(callback);
s_req->bcrypt_obj = bcrypt_obj;
s_req->rand_len = rand_len;

@@ -242,3 +241,2 @@ s_req->rounds = rounds;

ev_ref(EV_DEFAULT_UC);
bcrypt_obj->Ref();

@@ -248,4 +246,3 @@ return Undefined();

Handle<Value> BCrypt::GenerateSaltSync(const Arguments& args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> GenerateSaltSync(const Arguments& args) {
HandleScope scope;

@@ -282,9 +279,16 @@

/* ENCRYPT DATA - USED TO BE HASHPW */
int BCrypt::EIO_Encrypt(eio_req *req) {
#if NODE_LESS_THAN
int EIO_Encrypt(eio_req *req) {
#else
void EIO_Encrypt(eio_req *req) {
#endif
encrypt_request *encrypt_req = (encrypt_request *)req->data;
BCrypt *bcrypt_obj = (BCrypt *)encrypt_req->bcrypt_obj;
if (!(ValidateSalt(encrypt_req->salt))) {
encrypt_req->error = strdup("Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue");
return 0;
encrypt_req->error = "Invalid salt. Salt must be in the form of: $Vers$log2(NumRounds)$saltvalue";
#if NODE_LESS_THAN
return 1;
#else
return;
#endif
}

@@ -298,10 +302,12 @@

} catch (const char *err) {
encrypt_req->error = strdup(err);
encrypt_req->error = err;
free(bcrypted);
}
#if NODE_LESS_THAN
return 0;
#endif
}
int BCrypt::EIO_EncryptAfter(eio_req *req) {
int EIO_EncryptAfter(eio_req *req) {
HandleScope scope;

@@ -334,5 +340,3 @@

free(encrypt_req->output);
free(encrypt_req->error);
((BCrypt *)encrypt_req->bcrypt_obj)->Unref();
free(encrypt_req);

@@ -343,4 +347,3 @@

Handle<Value> BCrypt::Encrypt(const Arguments& args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> Encrypt(const Arguments& args) {
HandleScope scope;

@@ -360,6 +363,5 @@

if (!encrypt_req)
return ThrowException(Exception::Error(String::New("malloc in BCrypt::Encrypt failed.")));
return ThrowException(Exception::Error(String::New("malloc in Encrypt failed.")));
encrypt_req->callback = Persistent<Function>::New(callback);
encrypt_req->bcrypt_obj = bcrypt_obj;
encrypt_req->input = strdup(*data);

@@ -373,3 +375,2 @@ encrypt_req->salt = strdup(*salt);

ev_ref(EV_DEFAULT_UC);
bcrypt_obj->Ref();

@@ -379,4 +380,3 @@ return Undefined();

Handle<Value> BCrypt::EncryptSync(const Arguments& args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> EncryptSync(const Arguments& args) {
HandleScope scope;

@@ -425,5 +425,8 @@

int BCrypt::EIO_Compare(eio_req *req) {
#if NODE_LESS_THAN
int EIO_Compare(eio_req *req) {
#else
void EIO_Compare(eio_req *req) {
#endif
compare_request *compare_req = (compare_request *)req->data;
BCrypt *bcrypt_obj = (BCrypt *)compare_req->bcrypt_obj;

@@ -435,9 +438,10 @@ try {

} catch (const char *err) {
compare_req->error = strdup(err);
compare_req->error = err;
}
#if NODE_LESS_THAN
return 0;
#endif
}
int BCrypt::EIO_CompareAfter(eio_req *req) {
int EIO_CompareAfter(eio_req *req) {
HandleScope scope;

@@ -472,5 +476,2 @@

free(compare_req->input);
free(compare_req->error);
((BCrypt *)compare_req->bcrypt_obj)->Unref();
free(compare_req);

@@ -481,4 +482,3 @@

Handle<Value> BCrypt::Compare(const Arguments& args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> Compare(const Arguments& args) {
HandleScope scope;

@@ -498,5 +498,4 @@

if (!compare_req)
return ThrowException(Exception::Error(String::New("malloc in BCrypt::Compare failed.")));
return ThrowException(Exception::Error(String::New("malloc in Compare failed.")));
compare_req->callback = Persistent<Function>::New(callback);
compare_req->bcrypt_obj = bcrypt_obj;
compare_req->input = strdup(*input);

@@ -509,3 +508,2 @@ compare_req->encrypted = strdup(*encrypted);

ev_ref(EV_DEFAULT_UC);
bcrypt_obj->Ref();

@@ -515,4 +513,3 @@ return Undefined();

Handle<Value> BCrypt::CompareSync(const Arguments& args) {
BCrypt *bcrypt_obj = ObjectWrap::Unwrap<BCrypt>(args.This());
Handle<Value> CompareSync(const Arguments& args) {
HandleScope scope;

@@ -534,6 +531,15 @@

} // anonymous namespace
// bind the bcrypt module
extern "C" void init(Handle<Object> target) {
HandleScope scope;
BCrypt::Initialize(target);
NODE_SET_METHOD(target, "gen_salt_sync", GenerateSaltSync);
NODE_SET_METHOD(target, "encrypt_sync", EncryptSync);
NODE_SET_METHOD(target, "compare_sync", CompareSync);
NODE_SET_METHOD(target, "gen_salt", GenerateSalt);
NODE_SET_METHOD(target, "encrypt", Encrypt);
NODE_SET_METHOD(target, "compare", Compare);
};
#include "node_blf.h"
#include <pthread.h>
class BCrypt : public node::ObjectWrap {
static int EIO_GenSalt(eio_req *req);
static int EIO_GenSaltAfter(eio_req *req);
static int EIO_Encrypt(eio_req *req);
static int EIO_EncryptAfter(eio_req *req);
static int EIO_Compare(eio_req *req);
static int EIO_CompareAfter(eio_req *req);
public:
static void Initialize(v8::Handle<v8::Object> target);
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> GenerateSaltSync(const v8::Arguments& args);
static v8::Handle<v8::Value> EncryptSync(const v8::Arguments& args);
static v8::Handle<v8::Value> CompareSync(const v8::Arguments& args);
static v8::Handle<v8::Value> GenerateSalt(const v8::Arguments& args);
static v8::Handle<v8::Value> Encrypt(const v8::Arguments& args);
static v8::Handle<v8::Value> Compare(const v8::Arguments& args);
};
struct base_request {
v8::Persistent<v8::Function> callback;
void *bcrypt_obj;
char *error;
};
struct salt_request : base_request {
char *salt;
int salt_len;
int rand_len;
ssize_t rounds;
};
struct encrypt_request : base_request {
char *salt;
char *input;
char *output;
int output_len;
};
struct compare_request : base_request {
char *input;
char *encrypted;
bool result;
};

Sorry, the diff of this file is not supported yet