Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
This repository was archived by the owner on May 14, 2024. It is now read-only.

problems changing passwords #980

@byteAr

Description

@byteAr

I have had the problem that when trying to change the password of a user with valid credentials:

const ldap = require('ldapjs');

const ldapClient = ldap.createClient({
url: 'ldap://ipldap',
reconnect: true
});

const adminDN = 'cn=admin,cn=Users,dc=iugnad,dc=lan';
const adminPassword = 'passAdmin';

const searchFilter = '(sAMAccountName=mlopez)';

const searchOptions = {
scope: 'sub',
filter: searchFilter
};

ldapClient.bind(adminDN, adminPassword, (err) => {
if (err) {
console.error('Error LDAP:', err);
return;
}
console.log('Administrador autenticado correctamente.');

ldapClient.search('DC=example, DC=lan', searchOptions, (err, res) => {
if (err) {
console.error('Error User:', err);
return;
}

res.on('searchEntry', (entry) => {
  const userDN = entry.objectName;
  const newPassword= '********'
  console.log('DN del usuario encontrado:', userDN);

  const userCN = 'User';
 const userDN2 = `CN=${userCN},CN=Users,DC=iugnad,DC=lan`;

  const userPasswordAttribute = new ldap.Attribute({
    type: 'userPassword',
    vals: newPassword
  })

  ldapClient.modify(userDN2, 
    [
      new ldap.Change({
        operation: 'replace',
        modification: userPasswordAttribute
      })
    ],  
    (err) => {
    if (err) {
      console.log(err);
    } else {
      console.log('Password change successful');
    }
    ldapClient.unbind();
  });

I manage to log in and find the user to change the password. But when I change it I receive the following error:

ConnectionError: 1__ldap://servereldap:port closed
at C:\Users\mlopez\Desktop\prueba intranet\LDAP_Nodejs\node_modules\ldapjs\lib\client\client.js:1083:17
at C:\Users\mlopez\Desktop\prueba intranet\LDAP_Nodejs\node_modules\ldapjs\lib\client\message-tracker\index.js:113:7
at Map.forEach ()
at Object.purgeMessages [as purge] (C:\Users\mlopez\Desktop\prueba intranet\LDAP_Nodejs\node_modules\ldapjs\lib\client\message-tracker\index.js:110:14)
at Client._onClose (C:\Users\mlopez\Desktop\prueba intranet\LDAP_Nodejs\node_modules\ldapjs\lib\client\client.js:1081:11)
at Object.onceWrapper (node:events:633:26)
at Socket.emit (node:events:518:28)
at TCP. (node:net:337:12) {
lde_message: '1__ldap://10.98.40.22:389 closed',
lde_dn: null
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions