Skip to content

Commit 20ec792

Browse files
sokravesse
authored andcommitted
bcrypt is an optional dependency
1 parent 3b8112c commit 20ec792

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/ldapauth.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414

1515
var assert = require('assert');
16-
var bcrypt = require('bcrypt');
1716
var ldap = require('ldapjs');
1817
var debug = console.warn;
1918
var format = require('util').format;
@@ -84,7 +83,10 @@ function LdapAuth(opts) {
8483
this._adminBound = false;
8584
this._userClient = ldap.createClient(clientOpts);
8685

87-
this._salt = bcrypt.genSaltSync();
86+
if (opts.cache) {
87+
var bcrypt = require('bcrypt');
88+
this._salt = bcrypt.genSaltSync();
89+
}
8890
}
8991

9092

@@ -190,6 +192,7 @@ LdapAuth.prototype.authenticate = function (username, password, callback) {
190192
if (self.opts.cache) {
191193
// Check cache. 'cached' is `{password: <hashed-password>, user: <user>}`.
192194
var cached = self.userCache.get(username);
195+
var bcrypt = require('bcrypt');
193196
if (cached && bcrypt.compareSync(password, cached.password)) {
194197
return callback(null, cached.user)
195198
}
@@ -208,6 +211,7 @@ LdapAuth.prototype.authenticate = function (username, password, callback) {
208211
return callback(err);
209212
}
210213
if (self.opts.cache) {
214+
var bcrypt = require('bcrypt');
211215
bcrypt.hash(password, self._salt, function (err, hash) {
212216
self.userCache.set(username, {password: hash, user: user});
213217
return callback(null, user);

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
],
2424
"dependencies": {
2525
"ldapjs": "0.6.3",
26-
"bcrypt": "0.7.5",
2726
"lru-cache": "2.0.4"
27+
},
28+
"optionalDependencies": {
29+
"bcrypt": "0.7.5"
2830
}
2931
}

0 commit comments

Comments
 (0)