Issue #22 wontfix

change password by _LDAPUser

Anonymous avatarAnonymous created an issue

i needed this feature for my users ... changing theirs own ldap password.

I'll use this code some next weeks and my some tests are concluants with OpenLdap (self write ACL) tell me if i am crazy to use this code.

And may be you are interested to introduce this feature into THE py-django-ldap-backend ?

best regards

scr

class _LDAPUser(object):
...
class UpdatePasswordFailed(Exception):
    pass

def update_ldap_password(self, password, new_password):
    if self.dn is None:
        raise self.UpdatePasswordFailed("DN unknown")
    try:
        logger.debug(u"update password : %s / %s" % (password, new_password))
        self._bind_as(self.dn, password)
        ldap_cnx = self._get_connection().passwd_s(self.dn, password.encode('utf-8'),
new_password.encode('utf-8'))
        logger.info(u"Successfull password update for %s", self.dn)
    except self.ldap.INVALID_CREDENTIALS:
        logger.warn(u"Authentification failed for %s", self.dn)
        raise self.UpdatePasswordFailed(u"Authentification")
    except self.ldap.LDAPError, e:
        logger.error(u"Erreur Ldap (type: %s) :", type(e))
        logger.error(''.join(traceback.format_tb(sys.exc_info()[2])))
        raise self.UpdatePasswordFailed(u"Failed to update password !")

Comments (2)

  1. Peter Sagerson

    Thanks for the contribution. At present, django-auth-ldap limits itself to being a django.contrib.auth plugin and does not include any mechanisms to manipulate the directory. One of my projects also has need of this functionality and I implement it in a separate app that uses python-ldap directly (it's pretty straightforward). It's possible that password-changing will appear in a future version, as part of a more carefully thought-out design for supporting directory manipulation.

  2. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.