Error in Authenticate user usig active directory
Hello all, I new to active directory.. i have the following code to
create a new user and assign a group to that user... which create a
user in Local User and group section of Administrative tools/computer
managment .
// create user
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add(textUserName.Text, "user");
NewUser.Invoke("SetPassword", new object[] {textPassword.Text});
NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
NewUser.CommitChanges();
// assign group
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null)
{grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
MessageBox.Show("Account created successfully");
Here
is a code to authentcate user... but it gives a error like..."The
provider does not support searching and cannot search
WinNT://ADMIN,computer." I also confuse when to use "LDAP" protocol and
when "WinNT".
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Environment.MachineName + ",computer");
Object obj = AD.NativeObject;
DirectorySearcher directorySearcher = new DirectorySearcher(AD);
directorySearcher.Filter ="(SAMAccountName = " + textUserName.Text + ")";
directorySearcher.PropertiesToLoad.Add("cn");
SearchResult sr = directorySearcher.FindOne();
if (sr == null)
{
MessageBox.Show("Not Authenticated!!");
}
else
{
MessageBox.Show("Authenticated!!");
}
If anybody has a idea.. plz HELP...