G
G
GuessWh02016-12-05 15:00:24
ASP.NET
GuessWh0, 2016-12-05 15:00:24

How to check an attribute in Active Directory using c#?

Good afternoon!
Explain in which direction to dig, please.
I have a password reset form
e4d33ff996e944edac788074684d9e8d.jpg
where the data is filled in: username and TIN (TIN is written for each user in the employeeID attribute in AD). I want a check to be performed, if the username and TIN match, the password has changed

<tr>
            <td>
                <table width="350" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="180" align="right"><%=L_INN%></td>
                    <td width="7"></td>
                    <td align="right">
                    <input id="INN" name="INN" type="text" class="textInputField" runat="server" size="25" autocomplete="off" />
                    </td>
                </tr>
                </table>
            </td>
            </tr>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2016-12-05
@yarosroman

Here I have a user search in AD by name. You can create a filter in Active Directory Users & Computers.

SearchResultCollection adSearchResult;

            using (DirectoryEntry de = new DirectoryEntry("LDAP://esrr.oao.rzd"))
            {
                using (DirectorySearcher adSearch = new DirectorySearcher(de))
                {
                    adSearch.Filter = $"(&(objectCategory=person)(objectClass=user)(name={searchString}*)(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2))";
                    //adSearch.PropertiesToLoad.Add("displayName");
                    adSearchResult = adSearch.FindAll();

                }
            }

Oh, and password reset
public void ResetPassword(string userDn, string password)
{
    DirectoryEntry uEntry = new DirectoryEntry(userDn);
    uEntry.Invoke("SetPassword", new object[] { password });
    uEntry.Properties["LockOutTime"].Value = 0; //unlock account

    uEntry.Close();
}

Well, the whole thing is in the System.DirectoryServices assembly.
and in general
https://www.codeproject.com/articles/18102/howto-a...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question