PHPackages                             lzpeng/php-user-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. lzpeng/php-user-auth

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

lzpeng/php-user-auth
====================

用户认证核心库

1.0.3(5y ago)13701MITPHPPHP &gt;=7.0CI failing

Since Mar 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/liuzhanpeng/php-user-auth)[ Packagist](https://packagist.org/packages/lzpeng/php-user-auth)[ RSS](/packages/lzpeng-php-user-auth/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (1)Versions (6)Used By (1)

php-user-auth
=============

[](#php-user-auth)

用户认证核心库，目标是抽象并统一认证API, 各个php框架能在其之上快速实现一个稳定的用户认证库。

概念
--

[](#概念)

### 用户身份对象

[](#用户身份对象)

用于表示用户身份

### 用户身份对象提供器

[](#用户身份对象提供器)

对于不同系统，用户身份信息来源可能都不一样，可能来源于数据库、配置文件、甚至第三方系统等。

### 认证器

[](#认证器)

核心; 抽象用户认证API

### 认证管理器

[](#认证管理器)

组装内部组件，创建认证器

### 访问控制器

[](#访问控制器)

提供一个简单的基于资源的权限访问控制功能

### 权限资源提供器

[](#权限资源提供器)

权限资源可能来源于数据库、配置文件等，所以抽象出来

### 事件管理器

[](#事件管理器)

为认证器、访问控制器提供事件处理能力

基本使用方式
------

[](#基本使用方式)

// 配置 $config = \[ 'default' =&gt; 'test', 'authenticators' =&gt; \[ 'test' =&gt; \[ 'driver' =&gt; 'session', 'params' =&gt; \[ 'session\_key' =&gt; 'UserIdentity', \], 'provider' =&gt; \[ 'driver' =&gt; 'model', 'params' =&gt; \[ 'model' =&gt; \\app\\common\\model\\User::class, \] \], 'events' =&gt; \[ 'login\_before' =&gt; \[\] \] \], 'test2' =&gt; \[ 'driver' =&gt; 'token', 'params' =&gt; \[ 'token\_key' =&gt; 'user-token', \], 'provider' =&gt; \[ 'driver' =&gt; 'model', 'params' =&gt; \[ 'model' =&gt; \\app\\common\\model\\User::class, \] \], 'events' =&gt; \[ 'login\_before' =&gt; \[\] \] \] \] \];

$authManager = new AuthManager($config);

// 注册认证器 $authManager-&gt;registerAuthenticatorCreator('session', function($config) { // 认证器需要实现AuthenticatorInterface // 如果需要事件处理功能，需要实现EventableInterface接口 // 如果需要访问控制功能，需要实现AccessableInterface接口 // 或直接继承AbstractAuthenticator return new SessionAuthenticator($config\['session\_key'\]); }); // 注册用户提供器 $authManager-&gt;registerUserProviderCreator('model', function($config) { // 需要实现UserProviderinterface接口 return new ModelUserProvider($config\['model'\]); });

// 创建默认认证器 $authenticator = $authManager-&gt;create(); // 创建指定的认证器 // $authenticator = $authManger-&gt;create('test2');

// 登录 $authenticator-&gt;login(\[ 'username' =&gt; 'xxx', 'password' =&gt; '\*\*\*\*', \]);

// 是否已登录 $authenticator-&gt;isLogined();

// 获取用户 $user = $authenticator-&gt;user();

// 登出 $authenticator-&gt;logout();

扩展方式
----

[](#扩展方式)

扩展�认证库
------

[](#扩展认证库)

- [php-user-auth-think](https://github.com/liuzhanpeng/php-user-auth-think) ThinkPHP认证库

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

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.

###  Release Activity

Cadence

Every ~44 days

Total

4

Last Release

2112d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b085c9e9145b16a586a1574c9ece3fc1793c14c0d120f9f3c74b301b19165925?d=identicon)[liuzhanpeng](/maintainers/liuzhanpeng)

---

Top Contributors

[![liuzhanpeng](https://avatars.githubusercontent.com/u/6972018?v=4)](https://github.com/liuzhanpeng "liuzhanpeng (70 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lzpeng-php-user-auth/health.svg)

```
[![Health](https://phpackages.com/badges/lzpeng-php-user-auth/health.svg)](https://phpackages.com/packages/lzpeng-php-user-auth)
```

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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