Exemplo n.º 1
0
 /**
  * Sets the users password.
  *
  * @param   string  $new           New password.
  * @param   string  $old           Current password.
  * @param   string  $authenticate  Authenticate the old password before setting new.
  *
  * @return  boolean  True on success.
  *
  * @since   2.0
  */
 public function setPassword($new, $old = null, $authenticate = false)
 {
     if (is_null($this->_dn)) {
         $this->getId($authenticate);
     } elseif ($this->_dn instanceof Exception) {
         // Do not retry. Ldap configuration or user has problems.
         throw $this->_dn;
     }
     $hash = strtolower($this->client->passwordHash);
     $key = $this->getPassword(true);
     // Check if we need to authenticate and if so then do it
     if ($authenticate) {
         if (empty($old)) {
             throw new InvalidArgumentException(JText::_('LIB_SHUSERADAPTERSLDAP_ERR_10917', 10917));
         }
         if (!$this->client->bind($this->_dn, $old)) {
             // Incorrect old password
             throw new InvalidArgumentException(JText::_('LIB_SHUSERADAPTERSLDAP_ERR_10918', 10918));
         }
     }
     $password = $this->_genPassword($new);
     // Commit the Ldap password operation
     $this->client->replaceAttributes($this->_dn, array($key => $password));
     // Update the password inside this adapter
     $this->updateCredential($new);
     return true;
 }
Exemplo n.º 2
0
 public function testSlapdReplaceAttributesException()
 {
     $this->setExpectedException('SHLdapException', 'LIB_SHLDAP_ERR_10151', 10151);
     $ldap = new SHLdap(TestsHelper::getLdapConfig(214));
     $ldap->connect();
     $ldap->proxyBind();
     $user = TestsHelper::getUserCreds('trinity');
     // Try to replace an attribute that doesnt exist
     $this->assertTrue($ldap->replaceAttributes($user['dn'], array('attributedoesntexist' => array('asdasdas'))));
 }