PHPackages                             stmswitcher/yii2-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. stmswitcher/yii2-ldap-auth

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

stmswitcher/yii2-ldap-auth
==========================

Simple library to handle auth over LDAP in Yii 2 applications.

0.2(1y ago)24.4k↓11.1%6[1 issues](https://github.com/stmswitcher/yii2-ldap-auth/issues)[1 PRs](https://github.com/stmswitcher/yii2-ldap-auth/pulls)MITPHPPHP &gt;= 7.3

Since Jul 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/stmswitcher/yii2-ldap-auth)[ Packagist](https://packagist.org/packages/stmswitcher/yii2-ldap-auth)[ RSS](/packages/stmswitcher-yii2-ldap-auth/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

Yii2 LDAP Auth
==============

[](#yii2-ldap-auth)

Simple extension to handle auth over LDAP in Yii 2 applications.

**This extension intended for applications that rely *only* on LDAP authentication and does not support access tokens.**

Installation
============

[](#installation)

```
composer require "stmswitcher/yii2-ldap-auth"
```

Example of configuration and a use case
=======================================

[](#example-of-configuration-and-a-use-case)

Considering [yii2-app-basic](https://github.com/yiisoft/yii2-app-basic):

### Configure the component in your configuration file and change user identity class

[](#configure-the-component-in-your-configuration-file-and-change-user-identity-class)

```
'components' => [
    ...
    'ldapAuth' => [
        'class' => '\stmswitcher\Yii2LdapAuth\LdapAuth',
        'host' => 'your-ldap-hostname',
        'baseDn' => 'dc=work,dc=group',
        'searchUserName' => '',
        'searchUserPassword' => '',

        // optional parameters and their default values
        'ldapVersion' => 3,             // LDAP version
        'protocol' => 'ldaps://',       // Protocol to use
        'followReferrals' => false,     // If connector should follow referrals
        'port' => 636,                  // Port to connect to
        'loginAttribute' => 'uid',      // Identifying user attribute to look up for
        'ldapObjectClass' => 'person',  // Class of user objects to look up for
        'timeout' => 10,                // Operation timeout, seconds
        'connectTimeout' => 5,          // Connect timeout, seconds
    ],
    ...

    'user' => [
        'identityClass' => '\stmswitcher\Yii2LdapAuth\Model\LdapUser',
    ],
    ...
]
```

### Update methods in LoginForm class

[](#update-methods-in-loginform-class)

```
use stmswitcher\Yii2LdapAuth\Model\LdapUser;

...

public function validatePassword($attribute, $params)
{
    if (!$this->hasErrors()) {
        $user = LdapUser::findIdentity($this->username);

        if (!$user || !Yii::$app->ldapAuth->authenticate($user->getDn(), $this->password)) {
            $this->addError($attribute, 'Incorrect username or password.');
        }
    }
}

...

public function login()
{
    if ($this->validate()) {
        return Yii::$app->user->login(
            LdapUser::findIdentity($this->username),
            $this->rememberMe
                ? 3600*24*30 : 0
        );
    }
    return false;
}
```

### Verify that user belongs to LDAP group

[](#verify-that-user-belongs-to-ldap-group)

If you need also need to check if user is a member of certain LDAP group, use one more parameter for the `authenticate` function:

```
Yii::$app->ldapAuth->authenticate($user->getDn(), $this->password, 'cn=auth-user-group')
```

Now you can login with LDAP credentials to your application.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance21

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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.

###  Release Activity

Cadence

Every ~1415 days

Total

2

Last Release

725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8dfb0f34ecd9123b9b7f7980237fc7586e2d3db3a4c10e62bbdc3857c9d8279e?d=identicon)[stmswitcher](/maintainers/stmswitcher)

---

Top Contributors

[![stmswitcher](https://avatars.githubusercontent.com/u/10289021?v=4)](https://github.com/stmswitcher "stmswitcher (4 commits)")[![glukinov](https://avatars.githubusercontent.com/u/93668835?v=4)](https://github.com/glukinov "glukinov (1 commits)")

---

Tags

authyii2extensionldap

### Embed Badge

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

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

###  Alternatives

[kartik-v/yii2-password

Useful password strength validation utilities for Yii Framework 2.0

791.2M17](/packages/kartik-v-yii2-password)[chrmorandi/yii2-ldap

Ldap

1453.1k](/packages/chrmorandi-yii2-ldap)[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)[yiichina/yii2-auth

Yii2 中使用第三方登录扩展，包括：微博，QQ，微信，百度等

191.1k2](/packages/yiichina-yii2-auth)

PHPackages © 2026

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