2

I tried to reset a user password with the gem "devise_ldap_authenticatable" but it didn't work.

The command I tried to run was.

 Devise::LdapAdapter.update_password(login, new_password)

but it didn't work.

Unfortunately when it tries to bind it tries to bind the that user with a password nil since the old password is nil. I also tried to bind with the admin user credential but although the admin user is being logged in in; the password is not updated.

How would you reset a user ldap account password without using the 'old_password' as an admin user that have that privilege?

If you know a better solution, thanks to share!

Richardsondx
  • 1,227
  • 1
  • 15
  • 25

2 Answers2

3

Transmit a modify request to the server using a modification type of 'replace', an attribute type of whatever the password attribute is, and the new password value. The authorization state of the connection performing the modify request must have access rights to the password attribute or have password-reset rights.

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
  • I tried this: ldap.modify(:dn => "uid=test_1,ou=people,dc=sde,dc=myldapserver,dc=com", :ops => [:replace, :password, "hello"]) ldap.get_operation_result returns #. So it seem that the operation worked but when I tried to login with the new password it doesn't work. It seem that the operation is not being recorded. – Richardsondx May 06 '13 at 14:02
  • Ldap.modify(:dn => "uid=test_1,ou=people,dc=sde,dc=myserver,dc=com", :operations => [:replace, :unicodePwd, Iconv.conv('UTF-16LE', 'UTF-8', '"'+"hello"+'"')]) Your suggestion should work. The user I was using didn't have the right privileges. -_- I had to make a request to the infrastructure team..... (corporate -_-)..... Thanks! – Richardsondx May 06 '13 at 15:59
  • That almost worked for me. I had to do an additional step: `Iconv.conv('UTF-16LE', 'UTF-8', (?" + password + ?")).force_encoding('UTF-8')` – tamouse Feb 04 '15 at 01:15
0

If you don't want to rely on 'iconv':

unicodepwd = "\"#{plain_text_password}\"".encode(Encoding::UTF_16LE).
  force_encoding(Encoding::ASCII_8BIT)
andiba
  • 1,508
  • 2
  • 11
  • 22