Skip to content

Instantly share code, notes, and snippets.

@mtmcfarl
Created October 8, 2011 23:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtmcfarl/1273043 to your computer and use it in GitHub Desktop.
Save mtmcfarl/1273043 to your computer and use it in GitHub Desktop.
ruby net-ldap
class User < ActiveRecord::Base
attr_accessible :username, :password
SERVER = 'nwauth.uncg.edu'
PORT = 389
BASE = 'DC=uncg,DC=edu'
DOMAIN = 'uncg.edu'
def self.authenticate(username, password)
return nil if username.empty? or password.empty?
conn = Net::LDAP.new :host => SERVER,
:port => PORT,
:base => BASE,
:encryption => :simple_tls,
:auth => { :username => "#{username}@#{DOMAIN}",
:password => password,
:method => :simple }
if conn.bind
return true
else
return nil
end
rescue Net::LDAP::LdapError => e
return nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment