Created
October 8, 2011 23:16
-
-
Save mtmcfarl/1273043 to your computer and use it in GitHub Desktop.
ruby net-ldap
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
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