How to check windows login user name and password ?
I tried to user DirectoryEntry but it doesn't work.
Windows account
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Roei BarRank #1,271 · 1.4K reputationPosted Sep 24, 2009, 4:33 AM EDT
here is the code:
DirectoryEntry adsEntry = new DirectoryEntry(path, strAccountId, strPassword); DirectorySearcher adsSearcher = new DirectorySearcher( adsEntry ); //adsSearcher.Filter = "(&(objectClass=user)(objectCategory=person))"; adsSearcher.Filter = "(sAMAccountName=" + strAccountId + ")"; try { SearchResult adsSearchResult = adsSearcher.FindOne(); bSucceeded = true; strAuthenticatedBy = "Active Directory"; strError = "User has been authenticated by Active Directory."; adsEntry.Close(); } catch ( Exception ex ) { // Failed to authenticate. Most likely it is caused by unknown user // id or bad strPassword. strError = ex.Message; adsEntry.Close(); }