Created
August 24, 2016 03:03
-
-
Save yellowred/f96dfe8d5297eca0008bb6ef54e3bc9c to your computer and use it in GitHub Desktop.
change user password in LDAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let changePassword = (userId, passwordOld, passwordNew) => { | |
return new Promise((resolve, reject) => { | |
const ldapClient = ldapjs.createClient(ldapOptions); | |
// 1 | |
ldapClient.bind( | |
'cn=' + userId + ',' + ldapConfig.domain, | |
passwordOld, | |
err => { | |
if (err) return reject(err); | |
// 2 | |
ldapClient.modify(getDomainString(userId), | |
[ | |
new ldapjs.Change({ | |
operation: 'replace', | |
modification: { | |
userPassword: passwordNew | |
} | |
}) | |
], | |
(err) => { | |
if (err) reject(err); | |
return resolve(true); | |
} | |
); | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment