@@ -1191,32 +1191,30 @@ var _executeAuthCreateUserCommand = function(self, username, password, options,
1191
1191
roles = [ 'dbOwner' ] ;
1192
1192
}
1193
1193
1194
- const lastIsMaster = self . serverConfig . lastIsMaster ( ) ;
1194
+ const lastIsMaster = self . serverConfig . lastIsMaster ( ) || { } ;
1195
+
1196
+ const digestPassword = lastIsMaster . maxWireVersion >= 7 ;
1195
1197
1196
1198
// Build the command to execute
1197
- var command = {
1199
+ let command = {
1198
1200
createUser : username ,
1199
1201
customData : customData ,
1200
1202
roles : roles ,
1201
- digestPassword : false
1203
+ digestPassword
1202
1204
} ;
1203
1205
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
-
1212
1206
// Apply write concern to command
1213
1207
command = applyWriteConcern ( command , { db : self } , options ) ;
1214
1208
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
+ }
1220
1218
1221
1219
// No password
1222
1220
if ( typeof password === 'string' ) {
@@ -1299,6 +1297,9 @@ var addUser = function(self, username, password, options, callback) {
1299
1297
1300
1298
/**
1301
1299
* 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.
1302
1303
* @method
1303
1304
* @param {string } username The username.
1304
1305
* @param {string } password The password.
0 commit comments