index.js
function User(coll, username, opts) {
  if (typeof coll !== 'object') { throw new TypeError('coll must be an object'); }
  if (typeof username !== 'string') { throw new TypeError('username must be a string'); }

  // setup a resolver
  var db = {
    find: coll.findOne.bind(coll),
    insert: coll.insert.bind(coll),
    updateHash: function(lookup, hash, cb) {
      coll.update(lookup, { $set: { password: hash } }, function(err, updated) {
        if (err) { cb(err); return; }

        if (updated !== 1) { cb(new Error('failed to update password')); return; }

        cb(null);
      });
    }
  };

  BcryptUser.call(this, db, username, opts || {});
}
function User(coll, username, opts) {
  if (typeof coll !== 'object') { throw new TypeError('coll must be an object'); }
  if (typeof username !== 'string') { throw new TypeError('username must be a string'); }

  // setup a resolver
  var db = {
    find: coll.findOne.bind(coll),
    insert: coll.insert.bind(coll),
    updateHash: function(lookup, hash, cb) {
      coll.update(lookup, { $set: { password: hash } }, function(err, updated) {
        if (err) { cb(err); return; }

        if (updated !== 1) { cb(new Error('failed to update password')); return; }

        cb(null);
      });
    }
  };

  BcryptUser.call(this, db, username, opts || {});
}
function User ( coll , username , opts ) { if ( typeof coll !== 'object' ) { throw new TypeError ( 'coll must be an object' ) ; } if ( typeof username !== 'string' ) { throw new TypeError ( 'username must be a string' ) ; } // setup a resolver var db = { find : coll . findOne . bind ( coll ) , insert : coll . insert . bind ( coll ) , updateHash : function ( lookup , hash , cb ) { coll . update ( lookup , { $set : { password : hash } } , function ( err , updated ) { if ( err ) { cb ( err ) ; return ; } if ( updated !== 1 ) { cb ( new Error ( 'failed to update password' ) ) ; return ; } cb ( null ) ; } ) ; } } ; BcryptUser . call ( this , db , username , opts || { } ) ; }
Store and verify users with bcrypt passwords located in a mongodb collection.

@param {Object} coll  the database that contains all user accounts
@param {String} username  the name of the user to bind this instance to
@param {Object} [opts]  object containing optional parameters

opts:
realm {String, default "_default"}  optional realm the user belongs to
debug {Boolean, default false} whether to do extra console logging or not
hide {Boolean, default false} whether to suppress errors or not (for testing)
Store and verify users with bcrypt passwords located in a mongodb collection .