469,888 Members | 1,236 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,888 developers. It's quick & easy.

Create and authenticate user in AD

The following code is working fine, i can create the user in the Active
Directory and "enable" it.
My problem is that, when i'm trying to authenticate him, i can't get to
work!! The user and pass is correct, but it can't authenticate. If i try
other user created in the AD, it work just fine!!!

< Create User>

// Bind to the Users container, add a new user. Connecting with admin
DirectoryEntry de = new
de = de.Children.Find("CN=Users");

//Create the user
DirectoryEntry newUser = de.Children.Add("CN=" + txtLogin.Text, "user");

//Add the password
newUser.Password = txtPassword.Text;
.....(Search the user)...

//Bind User to AD to enable account
ActiveDs.IADsUser thisNewADSIuser = (ActiveDs.IADsUser)
thisNewADSIuser.AccountDisabled = false;

< Authenticate User>
//Connecting with user and password created in the "Create User" code...
DirectoryEntry entry = new
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(cn=" + username + ")";
SearchResult result = search.FindOne();

if(result == null)
return false;
catch (Exception ex)
{ return false; }

return true;

<--End Code-->

What i missed!? I try to search in the msdn (microsoft), but no luck!!
Nothing :(


Jul 21 '05 #1
0 1362

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Jason Shohet | last post: by
reply views Thread by Renato Neves | last post: by
1 post views Thread by EricRybarczyk | last post: by
1 post views Thread by fomalhaut | last post: by
reply views Thread by kang jia | last post: by
4 posts views Thread by Jon | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.