# Re: Net::LDAP 0.0.4 released

**URL:** <https://www.ruby-forum.com/t/re-net-ldap-0-0-4-released/65056>\
**Category:** Ruby\
**Created:** [August 15, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/re-net-ldap-0-0-4-released/65056 "2006-08-15T22:03:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [August 15, 2006, 10:03pm UTC](https://www.ruby-forum.com/t/re-net-ldap-0-0-4-released/65056/1 "2006-08-15T22:03:44Z")

</div>

> in comments, suggestions, feature requests, and patches. An  
> even bigger thank-you to the folks who have made themselves  
> available to help with testing.
> 
> Net::LDAP has been quite stable for several months now, so we  
> bumped the development status of the library up to Beta. We  
> will still be adding features and API improvements, but you  
> can assume that the current APIs and features will remain stable.
> 
> We’ve noticed that the Rails list gets regular chatter about  
> authentication and authorization.

I originally posted this on your forum page but I’ll post it here in  
case others find it useful.

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](http://ldap.foo.com) -LLL -b ou=People,[o=foo.com](http://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](http://ldap.foo.com) -LLL -D uid=djberge,ou=People,[o=foo.com](http://o=foo.com) -b  
ou=People,[o=foo.com](http://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?

Regards,

Dan

This communication is the property of Qwest and may contain confidential  
or  
privileged information. Unauthorized use of this communication is  
strictly  
prohibited and may be unlawful. If you have received this communication  
in error, please immediately notify the sender by reply e-mail and  
destroy  
all copies of the communication and any attachments.

---

<div class="post-metadata">

**Author:** ![BergerS\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bc8723/32.png) [@BergerS\_Daniel](https://www.ruby-forum.com/u/BergerS_Daniel)\
**Post date:** [August 15, 2006, 10:15pm UTC](https://www.ruby-forum.com/t/re-net-ldap-0-0-4-released/65056/2 "2006-08-15T22:15:45Z")

</div>

On 8/15/06, Berger, Daniel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> returned.  
> 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](http://ldap.foo.com)”

rs = ldap.bind\_as(  
:base =\> "ou=People,[o=foo.com](http://o=foo.com),  
:filter =\> “(uid=djberge)”,  
:password =\> “my\_pass”  
)

if rs

# you’re in

else

# you’re not

end

Does this work for you?
