PHPackages                             santran/ldap-auth - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. santran/ldap-auth

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

santran/ldap-auth
=================

LDAP Authentication for Laravel 5.2 and above

1578PHP

Since May 9Pushed 9y ago1 watchersCompare

[ Source](https://github.com/mrsantran/ldap-auth)[ Packagist](https://packagist.org/packages/santran/ldap-auth)[ RSS](/packages/santran-ldap-auth/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel 5 LDAP Authentication [Laravel 5.2+](http://laravel.com/)
=================================================================

[](#laravel-5-ldap-authentication-laravel-52)

[![Total Downloads](https://camo.githubusercontent.com/111d21583498e78c5d78c4704078d90c0c40b761d4c772c22c3e78de10229dfb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616e7472616e2f6c6461702d617574682e737667)](https://packagist.org/packages/santran/ldap-auth)[![Paypal Donate](https://camo.githubusercontent.com/7b6de155df30b37b25eb5fec52f9213680c3dbf067dfb7d7e2850ac4096c7d05/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f534d2e676966)](http://paypal.me/MrSanTran)

Installation
------------

[](#installation)

### Step 1: Install via composer

[](#step-1-install-via-composer)

```
    composer require santran/ldap-auth:dev-master

```

### Step 2: Add the Service Provider

[](#step-2-add-the-service-provider)

Modify your `config/app.php` file and add the service provider to the providers array.

```
    SanTran\LDAPAuth\LDAPAuthServiceProvider::class,
```

### Step 3: Publish the configuration file by running:

[](#step-3-publish-the-configuration-file-by-running)

```
    php artisan vendor:publish --tag="ldap_auth"

```

Now you're all set!

Configuration
-------------

[](#configuration)

### Step 1: Tweak the basic authentication

[](#step-1-tweak-the-basic-authentication)

Setup LDAP Server config `config/ldap_auth.php`.

```
return [
    'suffix' => '@127.0.0.1',

    /*
    |--------------------------------------------------
    | Domain Controllers
    |--------------------------------------------------
    |
    | The domain controllers option is an array of servers located on your
    | network that serve Active Directory. You can insert as many servers or
    | as little as you'd like depending on your forest (with a minimum of one).
    |
    */
    'domain_controller' => [
        '127.0.0.1'
    ],

    /*
    |--------------------------------------------------
    | Base Distinguished Name
    |--------------------------------------------------
    |
    | The base distinguished name is the base distinguished name you'd like
    | to perform operations on. An example base DN would be DC=dns,DC=example,DC=local.
    |
    | If none defined, then it will try to find it automatically by querying your server.
    | It's highly recommended to include it to limit queries executed per request.
    |
    */
    'base_dn' => 'DC=aitldap,DC=com',

    /*
    |--------------------------------------------------
    | Group Distinguished Name
    |--------------------------------------------------
    |
    | Permission login to this tool
    |
    */

    'group_dn' => 'CN=tms,OU=tools,DC=aitldap,DC=com',

    /*
    |--------------------------------------------------
    | Search Filter
    |--------------------------------------------------
    |
    | The filter option defines (you guessed it) on what filter to execute a query on.
    | The default filter is "uid". For more information please check
    | msdn.microsoft.com/En-US/library/aa746475.aspx
    |
    */

    'search_filter' => 'uid',

    /*
    |--------------------------------------------------
    | Search Fields
    |--------------------------------------------------
    |
    | The fields options defined what fields you want the be returned on a successful
    | query result. Note: The distinguished name is always returned.
    |
    */
    'search_fields' => [
        'cn',
        'gidNumber',
        'uid',
    ],

    'read_user_record' => true,

    'mapping_field' => "username",

    /*
    |--------------------------------------------------
    | Backup Rebinding
    |--------------------------------------------------
    |
    | This options indicates to use the host names sequentially. This package will try
    | to connect to the first domain controller. If it's not reachable the next DC
    | will be tried.
    |
    | If this option is set to false load balancing will be used instead for multiple DC.
    |
    */
    'backup_rebind' => true,

    /*
    |--------------------------------------------------
    | SSL & TLS
    |--------------------------------------------------
    |
    | One of these options are recommended if you have the ability to connect to your server
    | securely. Ensure that only one option can be true. The other one must be false.
    |
    */
    'ssl' => false,
    'tls' => false,

    /*
    |--------------------------------------------------------------------------
    | Administrator Username & Password
    |--------------------------------------------------------------------------
    |
    | When connecting to your AD server, an administrator username and
    | password is required to be able to query and run operations on
    | your server(s). You can use any user account that has
    | these permissions to prevent anonymous bindings.
    |
    */
    'admin_user' => 'Manager',
    'admin_pass' => '12345678',
];
```

Update your `config/auth.php` to use **ldap** as authentication and the **LDAPUser** Class.

```
'guards' => [
  	'web' => [
  		'driver'   => 'session',
  		'provider' => 'ldap',
	],
],

'providers' => [
	'users'      => [
		'driver' => 'eloquent',
		'model'  => App\User::class,
	],

	'ldap' => [
		'driver' => 'ldap',
		'model'  => \SanTran\LDAPAuth\LDAPUser::class,
	],
]
```

### Step 2: Adjust the LDAP config to your needs

[](#step-2-adjust-the-ldap-config-to-your-needs)

If you have run `php artisan vendor:publish --tag="ldap_auth"` you should see the
ldap\_auth.php file in your config directory. Adjust the values as you need them.

Usage
-----

[](#usage)

### Authentication

[](#authentication)

```
    if (auth()->attempt($request->only('username', 'password'))) {
        //Passed
    }
```

or

```
    $user = Auth::guard()->getProvider()->retrieveByCredentials($request->only('username', 'password'));
    if ($user && Auth::guard()
                ->getProvider()
                ->validateCredentials($user, $request->only('password')) && Auth::login($user)) {
        //Passed
    }
```

or

```
                $ldap = config('ldap_auth');
                $credentials = $request->only('username', 'password');
                $auth = config('auth');
                $model = $auth['providers']['ldap']['model'];
                $connection = new \SanTran\LDAPAuth\LDAP($ldap);
                $ldapp_auth = new \SanTran\LDAPAuth\LDAPAuthUserProvider($connection, $model);
                $user_ldap = $ldapp_auth->retrieveByCredentials($credentials);
                if ($ldapp_auth->validateCredentials($user_ldap, $credentials)) {
                    $user = User::where('username', '=', $credentials['username'])->first();
                    Auth::login($user, true);
		    //Passed
                } else {
                    return redirect()->back()->withInput()->with('error', trans('message.failed'));
                }
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/05fcc8d2c99d7c53346781ea21d01e043ed1cd1597675f83e2be8bb3fa868836?d=identicon)[santran](/maintainers/santran)

---

Top Contributors

[![mrsantran](https://avatars.githubusercontent.com/u/21286108?v=4)](https://github.com/mrsantran "mrsantran (17 commits)")

### Embed Badge

![Health badge](/badges/santran-ldap-auth/health.svg)

```
[![Health](https://phpackages.com/badges/santran-ldap-auth/health.svg)](https://phpackages.com/packages/santran-ldap-auth)
```

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

761.2M17](/packages/kartik-v-yii2-password)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
