authenticating using lightweight active directory services
I installed the lightweight active directory services using the guide
found here. I then went into the ADSI Edit and created a new user object.
I set the userPrincipleName to johndoe and I also set the password to
johndoe.
When creating the ADS, I used CN=partition1, DC=domain1, DC=com. I wanted
to write a little C# code to test authentication, but no matter what I do
it always fails to authenticate.
Here is what I have tried:
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ADTest
{
class Program
{
const string ActiveDirectoryDomain =
"localhost/CN=partition1,DC=domain1,DC=com";
static void Main(string[] args)
{
bool authenticated = false;
try
{
DirectoryEntry entry = new DirectoryEntry(
"LDAP://" + ActiveDirectoryDomain,
"johndoe",
"johndoe",
AuthenticationTypes.Secure);
if (entry.NativeObject != null)
{
authenticated = true;
}
}
catch (DirectoryServicesCOMException e)
{
}
}
}
}
Can someone tell me what I'm doing wrong? The exception I get is:
Logon failure: unknown user name or bad password. at
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
No comments:
Post a Comment