I'm would like to authenticate a username and password to my active directory. I've found many links using C# and one that connects me to show specific details of a user from a link below but not sure how to implement a password field into the lookup. Any help would be appreciated!!
https://community.progress.com/community_groups/f/27/t/22#
Sample:
DEFINE VARIABLE oADContext AS System.DirectoryServices.ActiveDirectory.DirectoryContext.
DEFINE VARIABLE oDirectoryEntry AS System.DirectoryServices.DirectoryEntry.
DEFINE VARIABLE oSearch AS System.DirectoryServices.DirectorySearcher.
DEFINE VARIABLE oResult AS System.DirectoryServices.SearchResult.
DEFINE VARIABLE oenum# AS System.Collections.IEnumerator.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE iItem AS INTEGER NO-UNDO.
DEFINE VARIABLE cUserName# AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPassword as character no-undo.
DEFINE VARIABLE cPath# AS CHARACTER NO-UNDO.
DEFINE VARIABLE cEmail AS CHARACTER NO-UNDO.
oADContext = NEW System.DirectoryServices.ActiveDirectory.DirectoryContext(System.DirectoryServices.ActiveDirectory.DirectoryContextType:Domain).
oDirectoryEntry = System.DirectoryServices.ActiveDirectory.Domain:GetDomain(oADContext):GetDirectoryEntry().
cUserName# = "usera".
cPassword = "mypassword".
oSearch = NEW System.DirectoryServices.DirectorySearcher(oDirectoryEntry,SUBSTITUTE("(&&(objectClass=user)(sAMAccountName=&1))",cUserName#)).
oResult = oSearch:FindOne().
/* now I've got the complete LDAP path of the Windows user */
oDirectoryEntry = NEW System.DirectoryServices.DirectoryEntry(oResult:path).
oenum# = oDirectoryEntry:Properties:GetEnumerator().
Thanks
Mark
It's much simpler if all you need to do is find out if a user name and password are valid. Here's some sample code.
/* This needs to be added to assemblies file */ USING System.DirectoryServices.AccountManagement.*. DEFINE VARIABLE objContext AS PrincipalContext. objContext = NEW PrincipalContext(ContextType:Domain,"YourDomain"). MESSAGE objContext:ValidateCredentials("TestUser","TestPasssword1") VIEW-AS ALERT-BOX.
It's much simpler if all you need to do is find out if a user name and password are valid. Here's some sample code.
/* This needs to be added to assemblies file */ USING System.DirectoryServices.AccountManagement.*. DEFINE VARIABLE objContext AS PrincipalContext. objContext = NEW PrincipalContext(ContextType:Domain,"YourDomain"). MESSAGE objContext:ValidateCredentials("TestUser","TestPasssword1") VIEW-AS ALERT-BOX.
Awesome! Thanks
One more minor point I should have mentioned. Passing NULL as both username and password will come back as true.
objContext:ValidateCredentials(?,?).
So make sure your code does not allow this.
Tom