Update Active Directory Password using ldap python

前端 未结 3 1738
你的背包
你的背包 2020-12-22 06:33

Basically trying to reset the user\'s password using LDAP python. I\'ve gone through various posts here but no luck :(.

Tried using :

  • a) mo

3条回答
  •  悲&欢浪女
    2020-12-22 07:30

    I think below program helpful for you.. windows active directory use password attribute as unicode method https://technet.microsoft.com/en-us/magazine/ff848710.aspx

    import ldap
    import ldap.modlist as modlist
    import base64
    ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    l = ldap.initialize('ldaps://exam.local')
    l.simple_bind_s('Administrator@exam.local', 'p@ssw0rd1') 
    dn="cn=map6,ou=Police,dc=exam,dc=local" 
    new_password='p@ssw0rd3'
    unicode_pass = unicode('\"' + new_password + '\"', 'iso-8859-1')
    print (unicode_pass)
    password_value = unicode_pass.encode('utf-16-le')
    add_pass = [(ldap.MOD_REPLACE, 'unicodePwd', [password_value])]
    print (password_value)
    l.modify_s(dn, add_pass)
    l.modify_s(dn, add_pass)
    l.unbind_s()      
    

提交回复
热议问题