Skip to content

Instantly share code, notes, and snippets.

@luizdamim
Created June 5, 2013 00:10
Show Gist options
  • Save luizdamim/5710683 to your computer and use it in GitHub Desktop.
Save luizdamim/5710683 to your computer and use it in GitHub Desktop.
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