Skip to content

Commit 1df6ab0

Browse files
daprahamianmbroadst
authored andcommitted
incorporating bernie's feedback
1 parent 708f16b commit 1df6ab0

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

lib/db.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,32 +1191,30 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
11911191
roles = ['dbOwner'];
11921192
}
11931193

1194-
const lastIsMaster = self.serverConfig.lastIsMaster();
1194+
const lastIsMaster = self.serverConfig.lastIsMaster() || {};
1195+
1196+
const digestPassword = lastIsMaster.maxWireVersion >= 7;
11951197

11961198
// Build the command to execute
1197-
var command = {
1199+
let command = {
11981200
createUser: username,
11991201
customData: customData,
12001202
roles: roles,
1201-
digestPassword: false
1203+
digestPassword
12021204
};
12031205

1204-
if (lastIsMaster && lastIsMaster.maxWireVersion >= 7) {
1205-
console.warn(
1206-
'Warning: creating a user against Server version >= 4.0 will enforce SCRAM-SHA-1 auth method'
1207-
);
1208-
1209-
command.mechanisms = ['SCRAM-SHA-1'];
1210-
}
1211-
12121206
// Apply write concern to command
12131207
command = applyWriteConcern(command, { db: self }, options);
12141208

1215-
// Use node md5 generator
1216-
var md5 = crypto.createHash('md5');
1217-
// Generate keys used for authentication
1218-
md5.update(username + ':mongo:' + password);
1219-
var userPassword = md5.digest('hex');
1209+
let userPassword = password;
1210+
1211+
if (!digestPassword) {
1212+
// Use node md5 generator
1213+
const md5 = crypto.createHash('md5');
1214+
// Generate keys used for authentication
1215+
md5.update(username + ':mongo:' + password);
1216+
userPassword = md5.digest('hex');
1217+
}
12201218

12211219
// No password
12221220
if (typeof password === 'string') {
@@ -1299,6 +1297,9 @@ var addUser = function(self, username, password, options, callback) {
12991297

13001298
/**
13011299
* Add a user to the database.
1300+
*
1301+
* NOTE: if you are connecting to MongoDB >= 4.0, the password will not be digested.
1302+
* We STRONGLY recommend that adding users be done exclusively over a TLS connection.
13021303
* @method
13031304
* @param {string} username The username.
13041305
* @param {string} password The password.

0 commit comments

Comments
 (0)