Created
June 5, 2013 00:10
-
-
Save luizdamim/5710683 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.DirectoryServices; | |
using System.DirectoryServices.Protocols; | |
using System.Net; | |
bool ValidateUser(string username, string password) | |
{ | |
bool authorized = false; | |
using(LdapConnection connection = new LdapConnection("192.168.0.5")) | |
{ | |
connection.AuthType = AuthType.Basic; | |
connection.AutoBind = false; | |
connection.Timeout = new TimeSpan(0, 0, 10); | |
connection.SessionOptions.ProtocolVersion = 3; | |
try | |
{ | |
var credential = new NetworkCredential(string.Format("uid={0},ou=Users,dc=domain,dc=com,dc=br", username), password); | |
connection.Bind(credential); | |
authorized = true; | |
} | |
catch (LdapException) | |
{ | |
// authentication failed | |
} | |
} | |
return authorized; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment