Setting password

Bjorn Ove Grotan bjorn.grotan at
Mon May 23 13:14:25 CEST 2005

Daniel LB:
> Hi
> Is it possible to set a user's password without knowing the old
> password with python-ldap?
> I have only come across the passwd(user,oldpw,newpw) function, which
> requires the old password, but if you are logged in as Administrator
> you should be able to *set* the users' password directly, no?

Just use the function modify_s to do such modifications.

import ldap
import ldap.modlist as modlist
newattrs = {'userPassword': '1337secret'}
old = l.search_s(base,ldap.SCOPE_SUBTREE,"uid=someuser",[])[0][1]['userPassword'][0]

# Given that you're binding with a user with read-priv to userPassword.
attrs = modlist.modifyModlist(old,newattrs)

# Alternatively, make a list of change-commands. I think its documented
# in the module, so just play along with help(ldap.modify_s) or
# something.

Bjørn Ove Grøtan

More information about the python-ldap mailing list