From: Francis Cianfrocca Date: 2006-08-16T05:13:45+09:00 Subject: Re: [ANN] Net::LDAP 0.0.4 released ------=_Part_32601_4847810.1155672822718 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 8/15/06, Berger, Daniel wrote: > > > I do two things with ldap - validation (does the user exist?) and > authentication (is this user/password combo correct?). For validation > (e.g. an admin adding a new user to the app) I use a command like this > (on Unix, add -x): > > ldapsearch -h ldap.foo.com -LLL -b ou=People,o=foo.com uid=djberge > > If 'djberge' is found, a record is returned. If not, nothing is > returned. > > For authentication (i.e. logging into the app) I use a command like this > (again, add -x on Unix): > > ldapsearch -h ldap.foo.com -LLL -D uid=djberge,ou=People,o=foo.com -b > ou=People,o=foo.com -w my_pass uid=djberge > > That returns a record if the user/password is legit or spews to stderr > if it's invalid. > > Can this be done with net-ldap? Get version 0.0.4 and read the Rdoc for Net::LDAP#bind_as . It should do what you're looking for. But one question: looking at your sample code, your first query binds anonymously. Is that permitted on your LDAP server? (Evidently it is, otherwise it wouldn't work for you!) I'm not sure Net::LDAP will handle an anonymous bind, because I don't have any directories that permit one. So you could try this code (which will bind anonymously to query the person record): require 'net/ldap' ldap = Net::LDAP.new ldap.host = "ldap.foo.com" rs = ldap.bind_as( :base => "ou=People,o=foo.com, :filter => "(uid=djberge)", :password => "my_pass" ) if rs # you're in else # you're not end Does this work for you? ------=_Part_32601_4847810.1155672822718--