# Ruby-ldap, invalid credentials

**URL:** <https://www.ruby-forum.com/t/ruby-ldap-invalid-credentials/48209>\
**Category:** Ruby\
**Created:** [November 17, 2005, 6:39pm UTC](https://www.ruby-forum.com/t/ruby-ldap-invalid-credentials/48209 "2005-11-17T18:39:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel.Berger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@Daniel.Berger](https://www.ruby-forum.com/u/Daniel.Berger)\
**Post date:** [November 17, 2005, 6:39pm UTC](https://www.ruby-forum.com/t/ruby-ldap-invalid-credentials/48209/1 "2005-11-17T18:39:40Z")

</div>

Hi all,

Another ldap newb question.

I can’t seem to bind to the ldap server with a password. For example,  
this works:

# ldaptest.rb

require “ldap”

ldap\_server = “[ldap.foo.com](http://ldap.foo.com)”  
password = “XXX”

ldap = LDAP::Conn.new(ldap\_server)  
ldap.simple\_bind(“cn=djberge,dc=foo,dc=bar,dc=com”)

However, if I try to password as the second argument to simple\_bind, I  
get an  
Invalid credentials (LDAP::ResultError). I’m positive the password is  
correct.

My main goal is to perform ldap authentication within a Rails  
controller. I  
thought I could just check success or failure on simple\_bind, but that  
doesn’t  
seem to be the case.

What am I doing wrong?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![Daniel.Berger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@Daniel.Berger](https://www.ruby-forum.com/u/Daniel.Berger)\
**Post date:** [November 18, 2005, 2:39pm UTC](https://www.ruby-forum.com/t/ruby-ldap-invalid-credentials/48209/2 "2005-11-18T14:39:04Z")

</div>

class LdapAdmin  
def initialize()  
@LDAP\_SERVER = ‘[ldap.lse.ac.uk](http://ldap.lse.ac.uk)’  
@LDAP\_BASE\_DN = ‘dc=linux,dc=lse,dc=ac,dc=uk’  
end

def login\_connect?(login, password)  
# test whether the login can connect to ldap with password  
# → true - yes  
# → false - no  
require ‘ldap’  
flag = false  
con = LDAP::Conn.new(@LDAP\_SERVER)  
con.set\_option(LDAP::LDAP\_OPT\_PROTOCOL\_VERSION, 3)  
begin  
con.bind(“cn=#{login},#{@LDAP\_BASE\_DN}”, password)  
con.unbind()  
flag = true  
rescue LDAP::ResultError  
flag = false  
end  
return flag  
end  
end

the above chunk of code works for me. the #{login} is admin and the  
password  
is the one specified in /etc/ldap/slapd.conf file (basically, i use it  
to  
log in to ldap admin account).

hope this helps,

vlad

---

<div class="post-metadata">

**Author:** ![Daniel.Berger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ac8455/32.png) [@Daniel.Berger](https://www.ruby-forum.com/u/Daniel.Berger)\
**Post date:** [November 18, 2005, 2:48pm UTC](https://www.ruby-forum.com/t/ruby-ldap-invalid-credentials/48209/3 "2005-11-18T14:48:06Z")

</div>

[http://pegacat.com/jxplorer/](http://pegacat.com/jxplorer/)

helps me a lot with ldap.

vlad
