Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment