Search code examples
pythondjangopython-3.xldap3

how to retrieve password in django 2.0?


Im using ldap for user authentication in django 2.0, and i need to create an endpoint to authenticate user from another application just passing the username to then redirect them. Isnt yet something to retrieve the raw password?


Solution

  • Using the **encrypt** method imported from **django_cryptography.fields**, define a password attribute for the model LdapProfile (model related to User to store the user profile on ldap) and then, use this password attribute in ldap.authenticate(username, password).

    password = encrypt(models.CharField(
        max_length=255,
            null=True,
            blank=True
        ))