summaryrefslogtreecommitdiff
path: root/src/mongo/shell/db.js
diff options
context:
space:
mode:
authorShreyas Kalyan <shreyas.kalyan@mongodb.com>2019-11-11 23:11:38 +0000
committerevergreen <evergreen@mongodb.com>2019-11-11 23:11:38 +0000
commitd2b75b4e2a6d1e9db7cbb6120c34b0b44476828e (patch)
treec23350b08e3102f883f8b1144276eaf5a1d9dc84 /src/mongo/shell/db.js
parent238daf3ed227a533cff14a34759c23b45d75e083 (diff)
downloadmongo-d2b75b4e2a6d1e9db7cbb6120c34b0b44476828e.tar.gz
SERVER-3788 version of auth() that prompts for password so it is never displayed
Diffstat (limited to 'src/mongo/shell/db.js')
-rw-r--r--src/mongo/shell/db.js11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/mongo/shell/db.js b/src/mongo/shell/db.js
index afc6e5357ed..5a10d55ff5f 100644
--- a/src/mongo/shell/db.js
+++ b/src/mongo/shell/db.js
@@ -1511,12 +1511,17 @@ DB.prototype._authOrThrow = function() {
if (arguments.length == 2) {
params = {user: arguments[0], pwd: arguments[1]};
} else if (arguments.length == 1) {
- if (typeof (arguments[0]) != "object")
+ if (typeof (arguments[0]) === "string") {
+ let password = passwordPrompt();
+ params = {user: arguments[0], pwd: password};
+ } else if (typeof (arguments[0]) === "object") {
+ params = Object.extend({}, arguments[0]);
+ } else {
throw Error("Single-argument form of auth expects a parameter object");
- params = Object.extend({}, arguments[0]);
+ }
} else {
throw Error(
- "auth expects either (username, password) or ({ user: username, pwd: password })");
+ "auth expects (username), (username, password), or ({ user: username, pwd: password })");
}
if (params.mechanism === undefined) {