Skip to content

Instantly share code, notes, and snippets.

@afbroman
Forked from masaki/gist:155854
Created May 17, 2013 18:15
Show Gist options
  • Save afbroman/5600900 to your computer and use it in GitHub Desktop.
Save afbroman/5600900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'active_ldap'
ActiveLdap::Base.setup_connection(
:host => 'ldap.example.com',
:base => 'dc=example,dc=com',
)
class User < ActiveLdap::Base
ldap_maping
class << self
def authenticate(dn, password)
user = find(dn)
user.bind(password)
user
rescue ActiveLdap::EntryNotFound,
ActiveLdap::AuthenticationError,
ActiveLdap::LdapError::UnwillingToPerform
nil
end
end
end
if $0 == __FILE__
p User.authenticate('foo', 'bar')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment