Guest User

Untitled

a guest
Jan 13th, 2018
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. class User < ActiveRecord::Base
  2.  
  3. attr_accessible :username, :password
  4.  
  5. SERVER = 'nwauth.uncg.edu'
  6. PORT = 389
  7. BASE = 'DC=uncg,DC=edu'
  8. DOMAIN = 'uncg.edu'
  9.  
  10. def self.authenticate(username, password)
  11. return nil if username.empty? or password.empty?
  12.  
  13. conn = Net::LDAP.new :host => SERVER,
  14. :port => PORT,
  15. :base => BASE,
  16. :encryption => :simple_tls,
  17. :auth => { :username => "#{username}@#{DOMAIN}",
  18. :password => password,
  19. :method => :simple }
  20. if conn.bind
  21. return true
  22. else
  23. return nil
  24. end
  25.  
  26. rescue Net::LDAP::LdapError => e
  27. return nil
  28.  
  29.  
  30. end
  31.  
  32. end
Add Comment
Please, Sign In to add comment