Click here to Skip to main content
15,908,111 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Dear everyone,

I have a system whose authentication and authorization depends on an Active Directory. The system does perform well with the AD except for just a constraint. For the system to work properly on a given machine where the system never been installed on I have to manually map the active directory server on the machine, for example if the OS is windows 7 or above I have to go into Credential Manager in control panel and set the server name and account to login to. This has to be done per installation. I want to avoid this situation.


Thanks
Posted
Updated 6-May-14 21:33pm
v3
Comments
ZurdoDev 7-May-14 7:59am    
You have to set credentials somehow. Either through code or this way or prompt the user.
Yonathan1111 8-May-14 7:33am    
OK Thanks! I hope I will find a way to overcome this situation.

1 solution

Try replacing your Authentication method.

C#
private bool Authenticate(string userName,
    string password, string domain)
{
    bool authentic = false;
    try
    {
        DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,
            userName, password);
        object nativeObject = entry.NativeObject;
        authentic = true;
    }
    catch (DirectoryServicesCOMException) { }
    return authentic;
}


thund3rstruck wrote a very nice article about working with Active Directory.
Howto: (Almost) Everything In Active Directory via C#[^]
 
Share this answer
 
Comments
Yonathan1111 8-May-14 7:38am    
Does the code will avoid the situation that I'm experiencing? Because the code I have is working fine with the AD authentication, once a credential mapping is done, it only fails for the first time, if the credential is not mapped.
wikus70 8-May-14 9:10am    
Well I only wrote one app that need AD authentication and that was a few years ago.
Back then I was told to do it this way because then you can add the username and password to an encrypted config file. So if the username and/or password changes you can just send a new encrypted config file to everyone using the program.
I'm not to sure what you do after the authentication process but I'm sure this code will work. Give it a try and if it doesn't I'll see if I can help you find another solution ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900