From 6e79f3004bd88584f6066283f2a5fb5796619680 Mon Sep 17 00:00:00 2001 From: rob Date: Sat, 24 Sep 2022 12:57:44 -0400 Subject: [PATCH] add user.updatePassword --- app/services/user.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/services/user.js b/app/services/user.js index 75a9eea..3b61e0c 100644 --- a/app/services/user.js +++ b/app/services/user.js @@ -667,6 +667,25 @@ class UserService extends SiteService { ); } + async updatePassword (user, password) { + const { crypto: cryptoService } = this.dtp.services; + + const passwordSalt = uuidv4(); + const passwordHash = cryptoService.maskPassword(passwordSalt, password); + + this.log.info('updating user password', { userId: user._id }); + + await User.updateOne( + { _id: user._id }, + { + $set: { + passwordSalt: passwordSalt, + password: passwordHash, + } + } + ); + } + /** * Updates the `lastAnnouncement` field of a User to the `created` date of the * specified announcement (for tracking last-seen announcements).