# LDAP and password protection

**URL:** <https://www.ruby-forum.com/t/ldap-and-password-protection/177350>\
**Category:** Rails\
**Created:** [October 15, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/ldap-and-password-protection/177350 "2009-10-15T14:28:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![michbukana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/4af34b/32.png) [@michbukana](https://www.ruby-forum.com/u/michbukana)\
**Post date:** [October 15, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/ldap-and-password-protection/177350/1 "2009-10-15T14:28:29Z")

</div>

Hello,

I’m implementing LDAP user authentication as in Enterprise Recipes With  
Ruby and Rails  
([http://pragprog.com/titles/msenr/enterprise-recipes-with-ruby-and-rails](http://pragprog.com/titles/msenr/enterprise-recipes-with-ruby-and-rails))  
and, according to the book, it is pretty simple, just as follows:

require ‘net/ldap’

class User  
BASE = ‘dc=enterpriserecipes,dc=com’  
LDAP\_USER = ‘cn=root,dc=enterpriserecipes,dc=com’  
LDAP\_PASSWORD = ‘t0p$ecret’

def self.authenticate(email, password)  
email\_filter = Net::LDAP::Filter.eq(‘mail’, email)  
ldap\_con = connect(LDAP\_USER, LDAP\_PASSWORD)  
dn = ‘’  
ldap\_con.search(:base =\> BASE, :filter =\> email\_filter) do |entry|  
dn = entry.dn  
end  
!dn.empty? and connect(dn, password).bind  
end

private

def self.connect(dn, password)  
Net::LDAP.new(  
:host =\> ‘localhost’,  
:port =\> 389,  
:auth =\> {  
:method =\> :simple,  
:username =\> dn,  
:password =\> password  
}  
)  
end  
end

Therefore, this is not secure, since I can see the user password in  
authenticate method. Does anyone know a way to hide the password from  
the developer, encrypting it or something?

Thanks for your time.
