Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Tue, 19 Apr 2005 16:21:33 +0100,    group: microsoft.public.platformsdk.active.directory        back       


Create and authenticate user in Active Directory   
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 
user...
DirectoryEntry de = new 
DirectoryEntry("LDAP://.....",txtLoginADmin.Text,txtPasswordADmin.Text);
de = de.Children.Find("CN=Users");

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

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


.....(Search the user)...

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

<------------------------------------------------------------------------------------------------------------->
<                                                       Authenticate User>
<------------------------------------------------------------------------------------------------------------->
//Connecting with user and password created in the "Create User" code...
DirectoryEntry entry = new 
DirectoryEntry("LDAP://.....",txtUserLogin.Text,txtUserPassword.Text);
try
{
//Bind to the native AdsObject to force authentication.
object obj = entry.NativeObject;

DirectorySearcher search = new DirectorySearcher(entry);

search.Filter = "(cn=" + username + ")";
search.PropertiesToLoad.Add("cn");
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 :(

Help!
date: Tue, 19 Apr 2005 16:21:33 +0100   author:   Renato Neves

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us