# LDAP Authentication with Username

**URL:** <https://www.ruby-forum.com/t/ldap-authentication-with-username/187469>\
**Category:** Ruby\
**Created:** [April 23, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/ldap-authentication-with-username/187469 "2010-04-23T17:17:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chromag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/71e660/32.png) [@chromag](https://www.ruby-forum.com/u/chromag)\
**Post date:** [April 23, 2010, 5:17pm UTC](https://www.ruby-forum.com/t/ldap-authentication-with-username/187469/1 "2010-04-23T17:17:12Z")

</div>

I’m trying to authenticate a username/password with Active Directory on  
our Windows SBS 2003 server. I have no problems if I auth with the CN  
set as the users full name, but I want to auth against the username  
instead. Here’s the code that works:

pass = “mypass”  
ldap = Net::LDAP.new  
ldap.host = “192.168.x.x”  
ldap.port = 389  
ldap.auth “CN=My  
Name,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=CompanyName,DC=local”, pass  
result = ldap.bind

This works great for the full name. If I change to the uid:

ldap.auth  
“UID=myusername,OU=SBSUsers,OU=Users,OU=MyBusiness,DC=CompanyName,DC=local”,  
pass

I get an authentication failure. I’m not that familiar with LDAP.  
Anyone have any idea how I should change the authentication string to  
auth against username instead of the full name?

Thanks.

---

<div class="post-metadata">

**Author:** ![chromag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/71e660/32.png) [@chromag](https://www.ruby-forum.com/u/chromag)\
**Post date:** [April 23, 2010, 6:05pm UTC](https://www.ruby-forum.com/t/ldap-authentication-with-username/187469/2 "2010-04-23T18:05:21Z")

</div>

Sorry for replying to my own email - but in case anyone else runs across  
this thread with this problem I found the obvious fix for it. The  
username should include the DOMAIN in it! Sheesh… so it turns out all  
I needed was simple authentication like this:

ldap.auth “MYDOMAIN\#{user}”, pass

Then when doing the bind it works perfectly.
