From ff04c8c504f28cef5470237c233ee57715a120a0 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 11 Sep 2013 09:52:58 +0200 Subject: [PATCH 1/2] bcrypt is an optional dependency --- lib/ldapauth.js | 8 ++++++-- package.json | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/ldapauth.js b/lib/ldapauth.js index 63c5d1e..7bc52b5 100644 --- a/lib/ldapauth.js +++ b/lib/ldapauth.js @@ -13,7 +13,6 @@ */ var assert = require('assert'); -var bcrypt = require('bcrypt'); var ldap = require('ldapjs'); var debug = console.warn; var format = require('util').format; @@ -81,7 +80,10 @@ function LdapAuth(opts) { this._adminBound = false; this._userClient = ldap.createClient(clientOpts); - this._salt = bcrypt.genSaltSync(); + if (opts.cache) { + var bcrypt = require('bcrypt'); + this._salt = bcrypt.genSaltSync(); + } } @@ -180,6 +182,7 @@ LdapAuth.prototype.authenticate = function (username, password, callback) { if (self.opts.cache) { // Check cache. 'cached' is `{password: , user: }`. var cached = self.userCache.get(username); + var bcrypt = require('bcrypt'); if (cached && bcrypt.compareSync(password, cached.password)) { return callback(null, cached.user) } @@ -198,6 +201,7 @@ LdapAuth.prototype.authenticate = function (username, password, callback) { return callback(err); } if (self.opts.cache) { + var bcrypt = require('bcrypt'); bcrypt.hash(password, self._salt, function (err, hash) { self.userCache.set(username, {password: hash, user: user}); return callback(null, user); diff --git a/package.json b/package.json index e419a1d..3866e64 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "engines": ["node >=0.8.0"], "dependencies": { "ldapjs": "0.6.3", - "bcrypt": "0.7.5", "lru-cache": "2.0.4" + }, + "optionalDependencies": { + "bcrypt": "0.7.5" } } From 66ce1d739817bfa54c8995ddade8bc2cace36dd6 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Wed, 11 Sep 2013 10:07:02 +0200 Subject: [PATCH 2/2] allow anonymous login --- lib/ldapauth.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ldapauth.js b/lib/ldapauth.js index 7bc52b5..5462ffe 100644 --- a/lib/ldapauth.js +++ b/lib/ldapauth.js @@ -52,7 +52,6 @@ var format = require('util').format; function LdapAuth(opts) { this.opts = opts; assert.ok(opts.url); - assert.ok(opts.adminDn); assert.ok(opts.searchBase); assert.ok(opts.searchFilter);