diff options
author | Miroslav Bajtoš <miroslav@strongloop.com> | 2014-04-25 12:11:46 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2014-05-01 21:20:44 +0400 |
commit | e772f1e66253f15350336391a26f084d121404fd (patch) | |
tree | 69707ce7f8cbaddeb7704ae1ee4462c75fd2fed1 /lib | |
parent | 2b80cfe8e9a1b32fa12d502c1a25b5b6c1b6c0a6 (diff) |
adduser: allow change of the saved password
Modify `npm adduser` to allow the user to change the password used
for authentication. This is useful when the password was changed
via the website and the user wants to update local npm config
to use this new password.
Before this change, `npm adduser` would not ask for a password when
the username was not changed, thus it was not possible to easily
change the password while keeping the same username.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/adduser.js | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/adduser.js b/lib/adduser.js index 739f14243..00d56383b 100644 --- a/lib/adduser.js +++ b/lib/adduser.js @@ -66,15 +66,17 @@ function readUsername (c, u, cb) { function readPassword (c, u, cb) { var v = userValidate.pw - if (!c.changed) { - u.p = c.p - return cb() - } read({prompt: "Password: ", silent: true}, function (er, pw) { if (er) { return cb(er.message === "cancelled" ? er.message : er) } + if (!c.changed && pw === '') { + // when the username was not changed, + // empty response means "use the old value" + pw = c.p + } + if (!pw) { return readPassword(c, u, cb) } @@ -85,6 +87,7 @@ function readPassword (c, u, cb) { return readPassword(c, u, cb) } + c.changed = c.changed || c.p != pw u.p = pw cb(er) }) |