Created
July 31, 2013 22:12
-
-
Save mrkplt/6126663 to your computer and use it in GitHub Desktop.
Ruby script using Net::LDAP (net/ldap) to authenticate a users account name against an ldap server. This is tested against an AD domain. user@example.com is not the user_name our domain expected. Your milage may vary. Credit to a bunch of tutorials for getting this to work (whose tabs I sadly closed). This shoudl enable you with the right creden…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ldap' | |
require 'io/console' | |
class LDAPUser | |
def connect(user_name, password) | |
ldap = Net::LDAP.new(:host => 'example.com', :port => 389) | |
ldap.auth("CN=#{user_name},OU=Users,DC=example,DC=com", password) | |
begin | |
answer = ldap.bind | |
rescue | |
answer = false | |
end | |
answer | |
end | |
end | |
puts 'User Name:' | |
user_name = STDIN.gets.chomp | |
puts 'Pass:' | |
password = STDIN.noecho(&:gets).chomp | |
user = LDAPUser.new | |
if user.connect(user_name, password) | |
puts 'Login Successful' | |
else | |
puts 'Login Failed' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment