1313 */
1414
1515var assert = require ( 'assert' ) ;
16- var bcrypt = require ( 'bcrypt' ) ;
1716var ldap = require ( 'ldapjs' ) ;
1817var debug = console . warn ;
1918var 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 ) ;
0 commit comments