# Net::LDAP

**URL:** <https://www.ruby-forum.com/t/net-ldap/130559>\
**Category:** Rails\
**Created:** [February 29, 2008, 11:40am UTC](https://www.ruby-forum.com/t/net-ldap/130559 "2008-02-29T11:40:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lokesh\_name](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/8c91f0/32.png) [@lokesh\_name](https://www.ruby-forum.com/u/lokesh_name)\
**Post date:** [February 29, 2008, 11:40am UTC](https://www.ruby-forum.com/t/net-ldap/130559/1 "2008-02-29T11:40:14Z")

</div>

Hi All,

I am new to Ruby and doing some automation testing.

I am using Net::LDAP to connect to my ldap server  
My script is

require ‘rubygems’  
require ‘net/ldap’

ldap = Net::LDAP.new :host =\> ‘10.44.169.24’,  
:port =\> 389,  
:auth =\> {  
:method =\> :simple,  
:username =\> “cn=Manager,dc=ibm,dc=com”,  
:password =\> “secret”  
}

#if ldap.bind  
#puts ldap.inspect  
#else  
#puts ldap.get\_operation\_result.message  
#end

filter = Net::LDAP::Filter.eq( “mail”, “removed\_email\_address@domain.invalid” )  
treebase = “dc=ibm,dc=com”  
attrs = [“userPassword”]  
ldap.search( :base =\> treebase, :filter =\> filter, :attributes =\> attrs  
) do |entry|

entry.each do |attribute, values|  
values.each do |value|  
puts “#{value}”

```
 end

```

end  
end

I am getting my expected result  
i.e.

mail=removed\_email\_address@domain.invalid,ou=people,o=external,dc=ibm,dc=com  
lI6z#f5C

Now I want to save the value lI6z#f5C (which is attribute password) and  
removed\_email\_address@domain.invalid in to 2 seperate variables say $passwd and $mail so  
that I can use these values for some other purpose.

Can anyone help me how can I do that.
