If I'm reading your question correctly, you have a Windows network login and a password, and you want to validate the user. Do you have to use LDAP?
This is what we use:
Public Function ValidateWindowsCredentials(ByVal UserId As String, _
ByVal Password As String) As Boolean
Dim Result As Boolean = False
Try
Dim PC As New PrincipalContext(ContextType.Domain, "OurDomain")
Result = PC.ValidateCredentials(UserId, Password, ContextOptions.Negotiate)
Result = PC.ValidateCredentials(UserId, Password, ContextOptions.Negotiate)
Catch ex As Exception
Throw ex
End Try
Return Result
End Function
My apologies for it being in VB, but you should be able to translate this to C# easily enough.
PrincipalContext
is part of the
System.DirectoryServices.AccountManagement
namespace, which was added to the 3.5 Framework (Visual Studio 2008) and, in my experience, it is significantly faster than older technique of trying to change the password to itself.
As far as obtaining a password from a user id, you cannot: the property is write-only. This is by design, to prevent a malicious user from writing code that could harvest network passwords out of the AD data store.