开发者

How to change ldap password using zend

I am working with zend framework, PHP , Ldap on Ubuntu. I am authenticating users from ldap using zend library. Now I want to change user's ldap passwords using zend. Any Idea?

This is the method that I am using to get zend authentication adapter. It is working perfectly and users are authenticated using this adapter.

public function getAuthAdapter(array $params)
{
        $front = Zend_Controller_Front::getInstance();

        $options = $front->getParam('bootstrap')->getOption('ldap');
        $params['username'] = split( "@" , $params['username'] );           
        $username = 'cn=' . $params['username'][0] . ',' . $options['server1']['baseDn'];                       
        $adapter = new Zend_Auth_Adapter_Ldap( $options, $username, $params['password']);

        $adapter->setIdentity( $params['username'] );
        $adapter->setCredential( $param开发者_如何学Pythons['password'] );

        return $adapter;
} 

Now how to change ldap passwords? Thanks


$ldap=new Zend_Ldap($options);
    $ldap->bind();      
    $entry=$ldap->getEntry($user->dn);
    $entry['userpassword'][0]=$newpassword;
    $ldap->save($user->dn, $entry);

This is how it worked form me! Note that I did not encript the password before sending but the server stored it with correct encription.


Use Zend_Auth_Adapter_Ldap for authenticating logins and such with an active directory.

For admin purposes of ldap, use Zend_Ldap.

Read the Zend documentation on the Zend_Ldap API, specifically the following

Zend_Ldap save(string|Zend_Ldap_Dn $dn, array $entry)

Saves the entry identified by $dn with its attributes $entry to the LDAP tree. Throws a Zend_Ldap_Exception if the entry could not be saved. This method decides by querying the LDAP tree if the entry will be added or updated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜