ruby-LDAP and password change?

D

Dick Davies

Just a quickie - anyone have a snippet to update a userPassword?
If not I'll knock one up and stick in on rubygarden..

Server is OpenLDAP, so exop would be great, but I'll settle for
anything.

Thanks.
 
O

Ollivier Robert

Just a quickie - anyone have a snippet to update a userPassword?
If not I'll knock one up and stick in on rubygarden..

It is like any modification to a given directory:

You need to hash the password:

-----
e_password = "{SHA}" + encode64(Digest::SHA1.new(password).digest).chomp
-----

then generate the modification:

-----
# Do the modification
#
reset = [
LDAP.mod(LDAP::LDAP_MOD_REPLACE, "userPassword", [e_password]),
]

conn.bind(USER, PASS) do
begin
conn.modify("uid=#{login},#{BASE}", reset)
rescue LDAP::ResultError => msg
puts "Can't change password: " + msg
exit 0
rescue LDAP::Error => errcode
puts "Can't change password: " + LDAP.err2string(errcode)
exit 0
end
end
-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,151
Messages
2,570,854
Members
47,394
Latest member
Olekdev

Latest Threads

Top