Skip to content

Instantly share code, notes, and snippets.

@mrkplt
Created July 31, 2013 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkplt/6126663 to your computer and use it in GitHub Desktop.
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…
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