question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow Change password in Active Directory

See original GitHub issue

In order to do a modify password in Active Directory (not admin reset) you need to create a single request with a Delete and then an Add of unicodePwd (https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-adts/6e803168-f140-4d23-b2d3-c3a8ab5917d2).

But, since ModifyAttributeCollection inherits from KeyedCollection<string, DirectoryAttribute> it does not allow adding 2 attributes with the same name.

What is the purpose for this instead of having it inherit from something like List<DirectoryModificationAttribute>?

I would be willing to do a pull request, but this is a potential breaking change…


var oldPasswordAttribute = new DirectoryModificationAttribute
{
    Name = "unicodePwd",
    LdapModOperation = Native.LdapModOperation.LDAP_MOD_DELETE
};

oldPasswordAttribute.Add(Encoding.Unicode.GetBytes($"\"{oldPassword}\""));

var newPasswordAttribute = new DirectoryModificationAttribute
{
    Name = "unicodePwd",
    LdapModOperation = Native.LdapModOperation.LDAP_MOD_ADD
};

newPasswordAttribute.Add(Encoding.Unicode.GetBytes($"\"{newPassword}\""));

var response = await _ldapConnection.Value.SendRequestAsync(new ModifyRequest(userDistinguishedName, oldPasswordAttribute, newPasswordAttribute));

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
flamencistcommented, Aug 27, 2020

@JManou FYI search attribute collection reverted to dictionary

1reaction
jaredrsowerscommented, Aug 26, 2020

And there is the option of doing something like this so that it has the same method signatures:

public class ModifyAttributeCollection : List<DirectoryModificationAttribute>
{
    public bool Contains(string name) =>
        this.Any(x => String.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));

    public DirectoryAttribute this[string name]
    {
        get
        {
            var item = this.FirstOrDefault(x => String.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));

            if (item == null)
            {
                throw new KeyNotFoundException();
            }

            return item;
        }
    }

    public bool TryGetValue(string name, out DirectoryAttribute item)
    {
        item = this.FirstOrDefault(x => String.Equals(x.Name, name, StringComparison.OrdinalIgnoreCase));

        if (item == null)
        {
            return false;
        }

        return true;
    }

    public bool Remove(string name)
    {
        var found = false;

        for (int i = 0; i < Count; i++)
        {
            if (String.Equals(this[i].Name, name, StringComparison.OrdinalIgnoreCase))
            {
                RemoveAt(i);
                --i;

                found = true;
            }
        }

        return found;
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ways to reset Active Directory Password | ADSelfService Plus
Log in to a domain-connected computer and open the Active Directory Users and Computers console. · Find the user account whose password you...
Read more >
How can I configure the system to let users change their ...
In the Permissions section, select the Allow check box for "Change Password." Click here to view image; Click OK to accept the changes....
Read more >
Permissions required to reset password on ADCU
Click Delegate Control to open the Delegation of Control Wizard. Click Next to proceed past the wizard's welcome page. Click Add . Click...
Read more >
How to delegate password reset permissions in Active ...
Right-click the object and select Delegate Control. active directory control wizard screen Beginning the Delegation of Control Wizard. The ...
Read more >
How to Change User Passwords in Active Directory
You simply right-click on a user account, select reset password, and providing you have the correct privileges on that account, you can reset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found