MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / changePassword

Function changePassword

services/cloudUser.js:90–135  ·  view source on GitHub ↗
(appId, userId, oldPassword, newPassword, accessList, isMasterKey, encryption_key)

Source from the content-addressed store, hash-verified

88 },
89
90 changePassword(appId, userId, oldPassword, newPassword, accessList, isMasterKey, encryption_key) {
91 const deferred = q.defer();
92
93 try {
94 customService.findOne(appId, Collections.User, {
95 _id: userId,
96 }, null, null, null, accessList, isMasterKey).then((user) => {
97 if (!user) {
98 deferred.reject('Invalid User');
99 return;
100 }
101 let encryptedPassword;
102 if (encryption_key && encryption_key.iv && encryption_key.key) {
103 encryptedPassword = encryptText(cipher_alg, encryption_key.key, encryption_key.iv, oldPassword);
104 } else {
105 encryptedPassword = crypto.pbkdf2Sync(oldPassword, config.secureKey, 10000, 64, 'sha1').toString('base64');
106 }
107 if (encryptedPassword === user.password) { // authenticate user.
108 if (encryption_key && encryption_key.iv && encryption_key.key) {
109 user.password = encryptText(cipher_alg, encryption_key.key, encryption_key.iv, newPassword);
110 } else {
111 user.password = crypto.pbkdf2Sync(newPassword, config.secureKey, 10000, 64, 'sha1').toString('base64');
112 }
113 mongoService.document.save(appId, [{
114 document: user,
115 }]).then(() => {
116 deferred.resolve(user); // returns no. of items matched
117 }, (error) => {
118 deferred.reject(error);
119 });
120 } else {
121 deferred.reject('Invalid Old Password');
122 }
123 }, (error) => {
124 deferred.reject(error);
125 });
126 } catch (err) {
127 winston.log('error', {
128 error: String(err),
129 stack: new Error().stack,
130 });
131 deferred.reject(err);
132 }
133
134 return deferred.promise;
135 },
136
137 /* Desc : Reset Password
138 Params : appId, email, accessList, masterKey

Callers

nothing calls this directly

Calls 3

findOneMethod · 0.80
encryptTextFunction · 0.70
saveMethod · 0.45

Tested by

no test coverage detected