Skip to content

Instantly share code, notes, and snippets.

@johnrails
johnrails / active_directory.rb
Created March 3, 2012 16:53
custom devise session controller for active directory users
def self.authenticate_user(username,password)
ldap = Net::LDAP.new
ldap.host = ActiveDirectory.first.host
ldap.port = 389
ldap.auth username, password
if ldap.bind
{:results => "successful", :message => "user authenticated"}
else
{ :results => "error", :message => ldap.get_operation_result.message}
end