Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="2.2.37"></a>
## [2.2.37](https://github.com/mongodb/node-mongodb-native/compare/v2.2.37...v2.2.37) (2018-10-22)


### Features

* **db, addUser**: Allow user creation with MongoDB versions > 4.0; automatically setting digest parameter and controlling digestion



<a name="2.2.35"></a>
## [2.2.35](https://github.com/mongodb/node-mongodb-native/compare/v2.2.34...v2.2.35) (2018-02-26)

Expand Down Expand Up @@ -1616,9 +1626,9 @@
* Reworked socket handling code to emit errors on unparsable messages
* Added logger option for Db class, lets you pass in a function in the shape
{
log : function(message, object) {},
error : function(errorMessage, errorObject) {},
debug : function(debugMessage, object) {},
log : function(message, object) {},
error : function(errorMessage, errorObject) {},
debug : function(debugMessage, object) {},
}

Usage is new Db(new Server(..), {logger: loggerInstance})
Expand Down
18 changes: 12 additions & 6 deletions lib/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -1263,22 +1263,28 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
roles = ['dbOwner']
}

const lastIsMaster = self.serverConfig.lastIsMaster() || {};
const digestPassword = lastIsMaster.maxWireVersion >= 7;

// Build the command to execute
var command = {
createUser: username
, customData: customData
, roles: roles
, digestPassword:false
, digestPassword: digestPassword
}

// Apply write concern to command
command = writeConcern(command, self, options);

// Use node md5 generator
var md5 = crypto.createHash('md5');
// Generate keys used for authentication
md5.update(username + ":mongo:" + password);
var userPassword = md5.digest('hex');
var userPassword = password;
if(!digestPassword){
// Use node md5 generator
var md5 = crypto.createHash('md5');
// Generate keys used for authentication
md5.update(username + ":mongo:" + password);
userPassword = md5.digest('hex');
}

// No password
if(typeof password == 'string') {
Expand Down