简体   繁体   中英

change password with python-ldap

I want change password on ldap user. The script is:

def changePassword(url,binddn,pw, newpw):
l = ldap.initialize(url)
ldap.
try:
    l.protocol_version=ldap.VERSION3
    l.simple_bind_s(binddn,pw)
except:
    print "Error Bind in changePassword"
    sys.exit(0)

old = {'userPassword':pw}
new = {'userPassword':newpw}
ldif = modlist.modifyModlist(old,new)
try:
    l.modify_s(binddn,ldif)
    l.unbind_s()
except:
    print "error"

But when I call this function, I receive "error". My LDAP has PPolicy for require current password when I change password.

How to change password whit this PPolicy??

Can anyone help me??

Thanks in advance Dario

With an LDAPv3 server, you should generally never do a direct mod/replace on a user password, and instead use the LDAPv3 Password modify operation. Using python-ldap, this is done with passwd/passwd_s. For example:

import ldap
server = 'localhost'
l = ldap.initialize('ldap://%s' % server)
l.simple_bind_s("cn=Marice McCaugherty,ou=Product Testing,dc=example,dc=com", "ytrehguaCc")
l.passwd_s("cn=Marice McCaugherty,ou=Product Testing,dc=example,dc=com", "ytrehguaCc", "secret")

Would bind as the user DN listed, and change their password from "ytrehguaCc" to "secret".

也许你必须直接在modify_s中使用以下modlist [(ldap.MOD_REPLACE,'userPassword',[newpasswd])]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM