Skip to content

Instantly share code, notes, and snippets.

@yellowred
Created August 24, 2016 03:03
Show Gist options
  • Save yellowred/f96dfe8d5297eca0008bb6ef54e3bc9c to your computer and use it in GitHub Desktop.
Save yellowred/f96dfe8d5297eca0008bb6ef54e3bc9c to your computer and use it in GitHub Desktop.
change user password in LDAP
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