2017 © Pedro Peláez
 

library ldap

My simple, crude LDAP package

image

mikebywater/ldap

My simple, crude LDAP package

  • Wednesday, March 30, 2016
  • by mikebywater
  • Repository
  • 1 Watchers
  • 2 Stars
  • 165 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 1 % Grown

The README.md

My Crude LDAP Class

Installation

Composer

To install simply put the following in your composer json file, (*1)

"require": {
        "mikebywater/ldap": "dev-master"
},

next simply run, (*2)

composer update

Parameters

ldap relies on global variables being set., (*3)

Laravel

In Laravel simply set the variables below in the .env file, (*4)

LDAP_SERVER =server.example.com
LDAP_DOMAIN=mydomain
LDAP_BASE_DSN=dc=example,dc=com
LDAP_ADMIN_USER=admin
LDAP_ADMIN_PASSWORD=password

Usage

Authenticating a user

use mikebywater\LDAP\LDAP as LDAP;
$ldap = new LDAP();
$username = 'testmember';
$password = 'test123';
if($ldap->authenticate($username,$password))
{
 echo "Authenticated";
}
else
{
    echo "Invalid Credentials";
}

Searching LDAP

use mikebywater\LDAP\LDAP as LDAP;
// Instantiate object
$ldap = new LDAP();
$username = "george.land";
// Method chaining allows us to bind to ldap, apply an ldap filter and get the first result
$entry = $ldap->bind()->filter("sAMAccountName=$username")->get()->first();

Extracting user Details from an entry

By using the LDAPUser class we can get user details from an entry, (*5)

use mikebywater\LDAP\LDAPUser as LDAPUser;
// Instantiating the object requires you to pass your ldap connection and the entry
// from the previous example
$user = new LDAPUser($ldap->conn, $entry);
$name =  $user->getName(); //special function for display name
$email = $user->getEmail(); //special function foe mail attributes
$company= $user->__get('company')[0]; // any other attribute can be grabbed with magic get method (beware will return an array)
$description= $user->__get('description')[0];

The Versions

30/03 2016

dev-master

9999999-dev

My simple, crude LDAP package

  Sources   Download

MIT

The Development Requires

by Mike Bywater

ldap