/**
  * Check if user exists and we can bind to the user
  *
  * @param $username
  * @param $password
  * @return array|bool
  */
 public function checkUser($username, $password)
 {
     $result = false;
     foreach ($this->getLDAPConnections() as $ldapConnection) {
         $filter = $this->getFeUsersFilter($ldapConnection, $username);
         $baseDn = $ldapConnection->getConfig()->getFeUsersBaseDn();
         $search = $ldapConnection->search($baseDn, $filter)->getFirstEntry();
         // try to bind as found user
         if ($search->countEntries() > 0) {
             $entry = $search->getLastEntry();
             $ldapUser = array();
             foreach ($search->getAttributes() as $attribute) {
                 $attribute = strtolower($attribute);
                 $imageField = LDAPConfigUtility::getImageAttribute($ldapConnection->getConfig()->getFeUsersMapping());
                 if (empty($imageField) || $attribute != $imageField) {
                     $ldapUser[$attribute] = $search->getValues($attribute);
                 } else {
                     if (!isset($ldapUser[$attribute])) {
                         $ldapUser[$attribute] = $search->getBinaryValues($attribute);
                     }
                 }
             }
             $ldapUser['dn'] = $username = $search->getDN($entry);
             try {
                 if ($ldapConnection->bind($username, $password)) {
                     $result = array('ldapUser' => $ldapUser, 'config' => $ldapConnection->getConfig());
                 }
             } catch (LDAPException $e) {
                 GeneralUtility::sysLog($e->getMessage(), 'ap_ldap_auth', GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
         }
     }
     return $result;
 }