当前位置: 首页>>代码示例>>PHP>>正文


PHP ldap_bind函数代码示例

本文整理汇总了PHP中ldap_bind函数的典型用法代码示例。如果您正苦于以下问题:PHP ldap_bind函数的具体用法?PHP ldap_bind怎么用?PHP ldap_bind使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了ldap_bind函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: lookup

 public static function lookup($query, $type)
 {
     $person_array = array();
     $x500 = ldap_connect('ldap.utexas.edu');
     $bind = ldap_bind($x500);
     $dn = "ou=people,dc=directory,dc=utexas,dc=edu";
     $filter = "{$type}={$query}";
     $ldap_result = @ldap_search($x500, $dn, $filter);
     $attributes = array('eid' => 'uid', 'email' => 'mail', 'name' => 'cn', 'firstname' => 'givenname', 'lastname' => 'sn', 'office' => 'utexasedupersonofficelocation', 'phone' => 'telephonenumber', 'title' => 'title', 'unit' => 'ou');
     if ($ldap_result) {
         $entry_array = ldap_get_entries($x500, $ldap_result);
         for ($i = 0; $i < count($entry_array) - 1; $i++) {
             $person = array();
             if ($entry_array[$i]) {
                 $eid = $entry_array[$i]['uid'][0];
                 foreach ($attributes as $label => $att) {
                     if (isset($entry_array[$i][$att])) {
                         $person[$label] = $entry_array[$i][$att][0];
                     } else {
                         $person[$label] = '';
                     }
                 }
             }
             $person_array[] = $person;
         }
         ldap_close($x500);
     }
     return $person_array;
 }
开发者ID:pkeane,项目名称:humptydumpty,代码行数:29,代码来源:Utlookup.php

示例2: __construct

 public function __construct($user)
 {
     $this->_id = $user;
     /* Connect to the IU's ADS server */
     $ds = ldap_connect(LDAP_HOST, LDAP_PORT) or die("Could not connect to ads.iu.edu:636 server");
     ldap_bind($ds, LDAP_USER . "," . LDAP_BASEDN, LDAP_PWD) or die("LDAP bind to ADS failed.");
     /* Search for a particular user information (Only required info) */
     $reqatr = array("mail", "displayName", "givenName", "title");
     $result = ldap_search($ds, LDAP_BASEDN, "(sAMAccountName={$this->_id})", $reqatr) or die("Search: No ADS entry has been found for the current user.");
     /* Each node in a directory tree has an entry. */
     $entry = ldap_first_entry($ds, $result);
     while ($entry) {
         /* Each entry is a set of attribute value pairs */
         /* Extracting only required values              */
         /* Also assuming there is only single value     */
         $this->_email = ldap_get_values($ds, $entry, "mail");
         $this->_email = $this->_email[0];
         /* Php 5.3 */
         $this->_name = ldap_get_values($ds, $entry, "displayName");
         if (is_null($this->_name)) {
             $this->_name = ldap_get_values($ds, $entry, "givenName");
         }
         $this->_name = $this->_name[0];
         /* Php 5.3 */
         $this->_instructor = ldap_get_values($ds, $entry, "title");
         $this->_instructor = $this->_instructor[0];
         /* Not expecting multiple entries */
         /* $entry = ldap_next_entry($ds, $result); */
         $entry = null;
     }
 }
开发者ID:pratapghanta,项目名称:Group-Evaluation,代码行数:31,代码来源:User.php

示例3: open

 protected function open()
 {
     $bind = \ldap_connect($this->ldap_server);
     \ldap_set_option($this->bind, LDAP_OPT_PROTOCOL_VERSION, 3);
     \ldap_bind($bind, $this->admin_user . ',' . $this->base_dn, $this->admin_password);
     $this->bind = $bind;
 }
开发者ID:guillaum3f,项目名称:codie,代码行数:7,代码来源:ldap.class.php

示例4: login_ad

function login_ad($user_, $pass_, $tipo_)
{
    //Comienzo la conexión al servidor para tomar los datos de active directory
    $host = get_config('host');
    $puerto = get_config('puerto');
    $filter = "sAMAccountName=" . $user_ . "*";
    $attr = array("displayname", "mail", "givenname", "sn", "useraccountcontrol");
    $dn = get_config('dn');
    $conex = ldap_connect($host, $puerto) or die("No ha sido posible conectarse al servidor");
    if (!ldap_set_option($conex, LDAP_OPT_PROTOCOL_VERSION, 3)) {
        echo "<br>Failed to set protocol version to 3";
    }
    if ($conex) {
        $dominio = get_config("dominio");
        $r = @ldap_bind($conex, $user_ . $dominio, $pass_);
        $existe = get_perfil($user_, $tipo_);
        if ($r && count($existe) > 0) {
            //LOGIN CORRECTO
            $result = ldap_search($conex, $dn, $filter, $attr);
            $entries = ldap_get_entries($conex, $result);
            for ($i = 0; $i < $entries["count"]; $i++) {
                $nombre = fix_data(utf8_decode($entries[$i]["givenname"][0]));
                $apellidos = fix_data(utf8_decode($entries[$i]["sn"][0]));
                $email = fix_data($entries[$i]["mail"][0]);
                //Acutalizar información desde AD en la tabla de empleados
                $s_ = "update empleados set nombre='{$nombre}', apellidos='{$apellidos}', mail='{$email}' where id='{$existe['id']}'";
                $r_ = mysql_query($s_);
                session_name("loginUsuario");
                session_start();
                $_SESSION['NAME'] = $nombre . " " . $apellidos;
                $_SESSION['USER'] = $user_;
                $_SESSION['IDEMP'] = $existe['id'];
                $_SESSION['AUSENCIA'] = get_ausencia($existe['id']);
                $_SESSION['DEPTO'] = $existe['depto'];
                $_SESSION['TYPE'] = $tipo_;
            }
            switch ($tipo_) {
                case "administrador":
                    header("Location: admin/inicio.php");
                    break;
                case "capturista":
                    header("Location: capturista/inicio.php");
                    break;
                case "autorizador":
                    header("Location: autorizador/scrap_firmar.php");
                    break;
                case "reportes":
                    header("Location: reportes/rep_general.php?op=listado");
                    break;
            }
        } else {
            echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php?error=2&user_={$user_}&tipo_={$tipo_}\">";
            exit;
        }
        ldap_close($conex);
    } else {
        echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"0; URL=index.php?error=3&user_={$user_}&tipo_={$tipo_}\">";
        exit;
    }
}
开发者ID:BrutalAndSick,项目名称:scrap,代码行数:60,代码来源:index11111.php

示例5: BackendSearchLDAP

 /**
  * Initializes the backend to perform the search
  * Connects to the LDAP server using the values from the configuration
  *
  *
  * @access public
  * @return
  * @throws StatusException
  */
 public function BackendSearchLDAP()
 {
     if (!function_exists("ldap_connect")) {
         throw new StatusException("BackendSearchLDAP(): php-ldap is not installed. Search aborted.", SYNC_SEARCHSTATUS_STORE_SERVERERROR, null, LOGLEVEL_FATAL);
     }
     // connect to LDAP
     $this->connection = @ldap_connect(LDAP_HOST, LDAP_PORT);
     @ldap_set_option($this->connection, LDAP_OPT_PROTOCOL_VERSION, 3);
     // Authenticate
     if (constant('ANONYMOUS_BIND') === true) {
         if (!@ldap_bind($this->connection)) {
             $this->connection = false;
             throw new StatusException("BackendSearchLDAP(): Could not bind anonymously to server! Search aborted.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
         }
     } else {
         if (constant('LDAP_BIND_USER') != "") {
             if (!@ldap_bind($this->connection, LDAP_BIND_USER, LDAP_BIND_PASSWORD)) {
                 $this->connection = false;
                 throw new StatusException(sprintf("BackendSearchLDAP(): Could not bind to server with user '%s' and specified password! Search aborted.", LDAP_BIND_USER), SYNC_SEARCHSTATUS_STORE_ACCESSDENIED, null, LOGLEVEL_ERROR);
             }
         } else {
             // it would be possible to use the users login and password to authenticate on the LDAP server
             // the main $backend has to keep these values so they could be used here
             $this->connection = false;
             throw new StatusException("BackendSearchLDAP(): neither anonymous nor default bind enabled. Other options not implemented.", SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED, null, LOGLEVEL_ERROR);
         }
     }
 }
开发者ID:alanturing1,项目名称:Z-Push-contrib,代码行数:37,代码来源:searchldap.php

示例6: authenticate

function authenticate($username, $password)
{
    global $config, $ldap_connection;
    if ($username && $ldap_connection) {
        if ($config['auth_ldap_version']) {
            ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, $config['auth_ldap_version']);
        }
        if (ldap_bind($ldap_connection, $config['auth_ldap_prefix'] . $username . $config['auth_ldap_suffix'], $password)) {
            if (!$config['auth_ldap_group']) {
                return 1;
            } else {
                $ldap_groups = get_group_list();
                foreach ($ldap_groups as $ldap_group) {
                    $ldap_comparison = ldap_compare($ldap_connection, $ldap_group, $config['auth_ldap_groupmemberattr'], get_membername($username));
                    if ($ldap_comparison === true) {
                        return 1;
                    }
                }
            }
        } else {
            echo ldap_error($ldap_connection);
        }
    } else {
        // FIXME return a warning that LDAP couldn't connect?
    }
    return 0;
}
开发者ID:Tatermen,项目名称:librenms,代码行数:27,代码来源:ldap.inc.php

示例7: __construct

 public function __construct($userKey)
 {
     $config = new Configuration();
     //try to connect to ldap if the settings are entered
     if ($config->ldap->host) {
         //If you are using OpenLDAP 2.x.x you can specify a URL instead of the hostname. To use LDAP with SSL, compile OpenLDAP 2.x.x with SSL support, configure PHP with SSL, and set this parameter as ldaps://hostname/.
         //note that connect happens regardless if host is valid
         $ds = ldap_connect($config->ldap->host);
         //may need ldap_bind( $ds, $username, $password )
         $bd = ldap_bind($ds) or die("<br /><h3>" . _("Could not connect to ") . $config->ldap->host . "</h3>");
         if ($bd) {
             $filter = $config->ldap->search_key . "=" . $userKey;
             $sr = ldap_search($ds, $config->ldap->base_dn, $filter);
             if ($entries = ldap_get_entries($ds, $sr)) {
                 $entry = $entries[0];
                 $fieldNames = array('fname', 'lname', 'email', 'phone', 'department', 'title', 'address');
                 foreach ($fieldNames as $fieldName) {
                     $configName = $fieldName . '_field';
                     $this->{$fieldName} = $entry[$config->ldap->{$configName}][0];
                 }
                 $this->fullname = addslashes($this->fname . ' ' . $this->lname);
             }
             ldap_close($ds);
         }
     }
 }
开发者ID:billdueber,项目名称:resources,代码行数:26,代码来源:LdapPerson.php

示例8: get_ldap_members

function get_ldap_members($group, $user, $password)
{
    global $ldap_host;
    global $ldap_dn;
    $LDAPFieldsToFind = array("member");
    print "{$ldap_host} {$ldap_dn}\n";
    $ldap = ldap_connect($ldap_host) or die("Could not connect to LDAP");
    // OPTIONS TO AD
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    ldap_bind($ldap, $user, $password) or die("Could not bind to LDAP");
    //check if group is just a name or an ldap string
    $group_cn = preg_match("/cn=/i", $group) ? $group : "cn={$group}";
    $results = ldap_search($ldap, $ldap_dn, $group_cn, $LDAPFieldsToFind);
    $member_list = ldap_get_entries($ldap, $results);
    $group_member_details = array();
    if (is_array($member_list[0])) {
        foreach ($member_list[0] as $list) {
            if (is_array($list)) {
                foreach ($list as $member) {
                    $member_dn = explode_dn($member);
                    $member_cn = str_replace("CN=", "", $member_dn[0]);
                    $member_search = ldap_search($ldap, $ldap_dn, "(CN=" . $member_cn . ")");
                    $member_details = ldap_get_entries($ldap, $member_search);
                    $group_member_details[] = array($member_details[0]['samaccountname'][0], $member_details[0]['displayname'][0], $member_details[0]['useraccountcontrol'][0]);
                }
            }
        }
    }
    ldap_close($ldap);
    array_shift($group_member_details);
    return $group_member_details;
    ldap_unbind($ldap);
}
开发者ID:LFCavalcanti,项目名称:pfsense-packages,代码行数:34,代码来源:dansguardian_ldap.php

示例9: authenticate

 /**
  * Authentication with username/password
  *
  * @access public
  * @param  resource $ldap
  * @param  string   $username
  * @param  string   $password
  * @return boolean
  */
 public function authenticate($ldap, $username, $password)
 {
     if (!ldap_bind($ldap, $username, $password)) {
         throw new ClientException('Unable to perform anonymous binding');
     }
     return true;
 }
开发者ID:Folcky,项目名称:kanboard,代码行数:16,代码来源:Client.php

示例10: LDAPLogin

function LDAPLogin($server = "mydomain.local", $username, $password, $domain = "mydomain", $dc = "dc=mydomain,dc=local")
{
    // https://www.exchangecore.com/blog/how-use-ldap-active-directory-authentication-php/
    $ldap = ldap_connect("ldap://{$server}");
    $ldaprdn = "{$domain}\\{$username}";
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
    $bind = @ldap_bind($ldap, $ldaprdn, $password);
    if ($bind) {
        $filter = "(sAMAccountName={$username})";
        $result = ldap_search($ldap, $dc, $filter);
        ldap_sort($ldap, $result, "sn");
        $info = ldap_get_entries($ldap, $result);
        if (!isset($info[0]["mail"][0])) {
            Log::createLog("danger", "ldap", "Unable to query LDAP, check base settings.");
            return null;
        }
        $data = array();
        $data["email"] = $info[0]["mail"][0];
        $data["lastname"] = $info[0]["sn"][0];
        $data["firstname"] = $info[0]["givenname"][0];
        @ldap_close($ldap);
        return $data;
    } else {
        Log::createLog("danger", "ldap", "Error: " . ldap_error($ldap));
    }
    return null;
}
开发者ID:DeltaWolf7,项目名称:Arc,代码行数:28,代码来源:login.php

示例11: authenticate

function authenticate($username, $password)
{
    global $error;
    sleep(1);
    $server = "ldap.rit.edu";
    //RIT LDAP Server
    $basedn = "ou=people,dc=rit,dc=edu";
    //Base DN
    $script = $_SERVER['SCRIPT_NAME'];
    $filter = "(uid={$username})";
    //$filter="(&(|(!(displayname=Administrator*))(!(displayname=Admin*)))(uid=$username))";    //define an appropriate ldap search filter to find your users, and filter out accounts such as administrator(administrator should be renamed anyway!).
    $dn = "uid={$username}, ";
    if (!($connect = ldap_connect($server))) {
        return 0;
    }
    ini_set("display_errors", "0");
    if (!($bind = ldap_bind($connect, "{$dn}" . $basedn, $password)) || empty($password)) {
        $error = "You either have a wrong username or wrong password";
        return 0;
    }
    ini_set("display_errors", "1");
    $sr = ldap_search($connect, $basedn, "{$filter}");
    $info = ldap_get_entries($connect, $sr);
    $_SESSION['accountUserName'] = $username;
    $_SESSION['accountFirstName'] = $info[0]['givenname'][0];
    $_SESSION['accountLastName'] = $info[0]['sn'][0];
    $_SESSION['accountPhone'] = $info[0]['telephonenumber'][0];
    $_SESSION['accountEmail'] = $info[0]['mail'][0];
    $_SESSION['accountType'] = $info[0]['riteduaccounttype'][0];
    return 1;
}
开发者ID:bjcpgd,项目名称:palserve,代码行数:31,代码来源:ldap.php

示例12: ldap_call

function ldap_call($connection, $bind_user, $bind_pass, $filter)
{
    $ds = ldap_connect($connection);
    //echo $connection . $bind_user . $bind_pass . $filter ;
    //personal e-mails
    if ($ds) {
        $r = ldap_bind($ds, $bind_user, $bind_pass);
        //$filter="(|(mail= null)(objectCategory=group))";
        $sr = ldap_search($ds, "ou=LMC, dc=lamontanita, dc=local", $filter);
        ldap_sort($ds, $sr, "cn");
        $info = ldap_get_entries($ds, $sr);
        //echo $info["count"] . " results returned:<p>";
        echo "<table id='ldaptable' border=1><tr><th>Name</th><th>E-mail</th></tr>";
        for ($i = 0; $i < $info["count"]; $i++) {
            if ($info[$i]["mail"][0] != null) {
                echo "<td>" . $info[$i]["cn"][0] . "</td>";
                echo "<td>" . $info[$i]["mail"][0] . "</td></tr>";
            }
        }
        echo "</table>";
        return $info;
        ldap_close($ds);
    } else {
        echo "<h4>LDAP_CALL unable to connect to LDAP server</h4>";
    }
}
开发者ID:stpmt11,项目名称:phpos,代码行数:26,代码来源:functions.php

示例13: is_prof

function is_prof($login)
{
    global $ldap_server, $ldap_port, $dn;
    global $error;
    $error = "";
    $filter = "(&(cn=profs*)(memberUid={$login}))";
    $ldap_groups_attr = array("cn", "memberUid");
    /*-----------------------------------------------------*/
    $ds = @ldap_connect($ldap_server, $ldap_port);
    if ($ds) {
        $r = @ldap_bind($ds);
        if (!$r) {
            $error = "Echec du bind anonyme";
        } else {
            // Recherche du groupe d'appartenance de l'utilisateur connecte
            $result = @ldap_list($ds, $dn["groups"], $filter, $ldap_groups_attr);
            if ($result) {
                $info = @ldap_get_entries($ds, $result);
                if ($info["count"]) {
                    $is_prof = true;
                } else {
                    $is_prof = false;
                }
            }
        }
    }
    @ldap_unbind($ds);
    @ldap_close($ds);
    return $is_prof;
}
开发者ID:rhertzog,项目名称:lcs,代码行数:30,代码来源:init_users_lcs.php

示例14: checkLogin

 public function checkLogin($username, $password)
 {
     if (!$username || !$password) {
         return false;
     }
     $username = $this->escapeUsername($username);
     if (!$username) {
         return false;
     }
     $this->bind();
     $dn = 'cn=' . $username . ',' . $this->config['dn'];
     $authenticated = ldap_bind($this->connection, $dn, $password);
     if (!$authenticated) {
         return false;
         // User details where invalid
     }
     $result = ldap_search($this->connection, $this->config['dn'], 'cn= ' . $username);
     if (!$result) {
         return false;
         // Couldn't find user
     }
     $info = ldap_get_entries($this->connection, $result);
     $user_id = intval($info[0]['uid'][0]);
     if (!$user_id) {
         return false;
         // No user_id defined, or invalid
     }
     return $user_id;
     // Login successful
 }
开发者ID:thibmo,项目名称:hackthis.co.uk,代码行数:30,代码来源:class.ldap.php

示例15: __construct

 /**
  * Connection to the database
  *
  */
 public function __construct()
 {
     $this->domain = $domain;
     parent::__construct();
     require FRAMEWORK . DS . 'conf' . DS . 'datastore.php';
     $config = $datastore[$this->datastore];
     if (!isset(self::$connection[$this->datastore])) {
         self::$connection[$this->datastore] = @ldap_connect($config['protocol'] . $config['domain']);
         if (!self::$connection[$this->datastore]) {
             throw new connectException('Could not connect to the Active Directory.');
         }
         ldap_set_option(self::$connection[$this->datastore], LDAP_OPT_REFERRALS, 0);
         ldap_set_option(self::$connection[$this->datastore], LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@ldap_bind(self::$connection[$this->datastore], $config['user'] . '@' . $config['domain'], $config['password'])) {
             throw new connectException('Could not bind to the Active Directory.');
         }
     }
     $this->con =& self::$connection[$this->datastore];
     $this->dn = $config['dn'];
     $config2 = $datastore[$this->datastore2];
     if (!isset(self::$connection[$this->datastore2])) {
         self::$connection[$this->datastore2] = @ldap_connect($config2['protocol'] . $config2['domain']);
         if (!self::$connection[$this->datastore2]) {
             throw new connectException('Could not connect to the Active Directory.');
         }
         ldap_set_option(self::$connection[$this->datastore2], LDAP_OPT_REFERRALS, 0);
         ldap_set_option(self::$connection[$this->datastore2], LDAP_OPT_PROTOCOL_VERSION, 3);
         if (!@ldap_bind(self::$connection[$this->datastore2], $config2['user'] . '@' . $config2['domain'], $config2['password'])) {
             throw new connectException('Could not bind to the Active Directory.');
         }
     }
     $this->con2 =& self::$connection[$this->datastore2];
     $this->dn2 = $config2['dn'];
     $this->attributes = array_keys($this->mapping);
 }
开发者ID:nephie,项目名称:AZL-website,代码行数:39,代码来源:admodel.php


注:本文中的ldap_bind函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。