<p>Given a username and a password for a domain user, what would be the best way to authenticate that user programatically?</p>

[{'answer_id': 31665, 'author': 'David J. Sokol', 'author_id': 1390, 'author_profile': 'https://Stackoverflow.com/users/1390', 'pm_score': 3, 'selected': False, 'text': '<p>You can use some hacks to <strong>authenticate</strong> only.</p>\n\n<pre><code>Try\n    Dim directoryEntry as New DirectoryEntry("LDAP://DomainController:389/dc=domain,dc=suffix", "username", "password")\n    Dim temp as Object = directoryEntry.NativeObject\n    return true\nCatch\n    return false\nEnd Try\n</code></pre>\n\n<p>If the user is not valid, the directory entry NativeObject cannot be accessed and throws an exception.  While this isn\'t the most efficient way (exceptions are evil, blah blah blah), it\'s quick and painless.  This also has the super-cool advantage of working with all LDAP servers, not just AD.</p>\n'}, {'answer_id': 32669, 'author': 'John Christensen', 'author_id': 1194, 'author_profile': 'https://Stackoverflow.com/users/1194', 'pm_score': 4, 'selected': False, 'text': '<p>It appears that .NET 3.5 added a new namespace to deal with this issue - System.DirectoryServices.AccountManagement. Code sample is below:</p>\n\n<pre><code>Private Function ValidateExternalUser(ByVal username As String, ByVal password As String) As Boolean\n    Using context As PrincipalContext = New PrincipalContext(ContextType.Domain, _defaultDomain)\n        Return context.ValidateCredentials(username, password, ContextOptions.Negotiate)\n    End Using\nEnd Function\n</code></pre>\n\n<p>The namespace also seems to provide a lot of methods for manipulating a domain account (changing passwords, expiring passwords, etc). </p>\n'}]
['https://Stackoverflow.com/questions/30861', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1194/']