PHPackages                             tourze/biz-user-bundle - 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. tourze/biz-user-bundle

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

tourze/biz-user-bundle
======================

基础的业务用户管理模块

0.0.4(11mo ago)01.7k1MITPHPPHP ^8.1CI passing

Since May 9Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/biz-user-bundle)[ Packagist](https://packagist.org/packages/tourze/biz-user-bundle)[ RSS](/packages/tourze-biz-user-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (39)Versions (5)Used By (1)

biz-user-bundle
===============

[](#biz-user-bundle)

[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://php.net)[![Symfony Version](https://camo.githubusercontent.com/f8657920fcda649d7395bd409826245a37404b0e247437f78b29601093c66565/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253545362e342d677265656e)](https://symfony.com)[![License](https://camo.githubusercontent.com/88e1dabf4d223df0950e0985948e231325fefca9fa7fe9e446cf8b1c5e9d9e47/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e)](LICENSE)[![Build Status](https://camo.githubusercontent.com/b0c6c6845a74cb65a7f0a32bdcfd8fbf80eeb40026c4029af424ab371c94b8bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e)](tests)[![Code Coverage](https://camo.githubusercontent.com/32855e94577df9d0a30995653b17d33a5fbfdf644518f96ea0374313397d19b7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e)](tests)[![Tests](https://camo.githubusercontent.com/d940ad7f0752e2cbe0d63c50dcebf329078807390051c41fe63258f1b5c4e182/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d70617373696e672d627269676874677265656e)](tests)

[English](README.md) | [中文](README.zh-CN.md)

Business user management bundle for Symfony applications.

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Configuration](#configuration)
- [Quick Start](#quick-start)
- [Basic Usage](#basic-usage)
- [Advanced Usage](#advanced-usage)
- [Events](#events)
- [Security](#security)
- [Testing](#testing)
- [License](#license)

Features
--------

[](#features)

- **User Management**: Complete user entity with authentication support
- **Password Management**: Password history tracking and strength validation
- **Role Management**: Integration with BizRole system for user permissions
- **User Migration**: Advanced user data migration and merging capabilities
- **Attribute System**: Integration with user-attribute-bundle for flexible user data
- **Admin Interface**: EasyAdmin integration for user management
- **Event System**: Events for user identity lookups
- **Security Features**: Password strength validation, history tracking

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

[](#installation)

```
composer require tourze/biz-user-bundle
```

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

[](#configuration)

### 1. Register the Bundle

[](#1-register-the-bundle)

```
// config/bundles.php
return [
    // ...
    BizUserBundle\BizUserBundle::class => ['all' => true],
];
```

### 2. Configure Services

[](#2-configure-services)

The bundle automatically registers its services. You can override them in your application:

```
# config/services.yaml
services:
    # Override user service
    BizUserBundle\Service\UserService:
        arguments:
            $passwordHistoryLimit: 5  # Number of previous passwords to check
```

Quick Start
-----------

[](#quick-start)

After installation, follow these steps to get started quickly:

### 1. Configure the Bundle

[](#1-configure-the-bundle)

```
// config/bundles.php
return [
    // ...
    BizUserBundle\BizUserBundle::class => ['all' => true],
];
```

### 2. Create Your First User

[](#2-create-your-first-user)

```
use BizUserBundle\Entity\BizUser;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;

// In your controller or service
$user = new BizUser();
$user->setUsername('admin@example.com');
$user->setEmail('admin@example.com');
$user->setNickName('Administrator');
$user->setValid(true);

// Hash the password
$hashedPassword = $passwordHasher->hashPassword($user, 'SecurePass123!');
$user->setPasswordHash($hashedPassword);

$entityManager->persist($user);
$entityManager->flush();
```

### 3. Find and Authenticate Users

[](#3-find-and-authenticate-users)

```
use BizUserBundle\Service\UserService;

// Find a user by username or email
$user = $userService->findUserByIdentity('admin@example.com');

// Check if user is admin
if ($userService->isAdmin($user)) {
    // Grant admin access
}
```

### 4. Validate Password Strength

[](#4-validate-password-strength)

```
try {
    $userService->checkNewPasswordStrength($user, 'newPassword123!');
    echo "Password is strong enough!";
} catch (PasswordWeakStrengthException $e) {
    echo "Password too weak: " . $e->getMessage();
}
```

Basic Usage
-----------

[](#basic-usage)

### User Entity

[](#user-entity)

The `BizUser` entity provides a complete user implementation:

```
use BizUserBundle\Entity\BizUser;

$user = new BizUser();
$user->setUsername('john.doe@example.com');
$user->setNickName('John Doe');
$user->setEmail('john.doe@example.com');
$user->setPlainPassword('securePassword123!');
```

### User Service

[](#user-service)

The `UserService` provides various user operations:

```
use BizUserBundle\Service\UserService;

// Find user by identity
$user = $userService->findUserByIdentity('john.doe@example.com');

// Check password strength
$userService->checkNewPasswordStrength($user, 'newPassword123!');

// Check if user is admin
$isAdmin = $userService->isAdmin($user);
```

### Password History

[](#password-history)

Track password history to prevent reuse:

```
use BizUserBundle\Entity\PasswordHistory;

$history = new PasswordHistory();
$history->setUser($user);
$history->setPasswordHash($hashedPassword);
```

Advanced Usage
--------------

[](#advanced-usage)

### Admin Controllers

[](#admin-controllers)

The bundle provides ready-to-use EasyAdmin controllers:

- `BizUserCrudController` - User management with full CRUD operations
- `PasswordHistoryCrudController` - Password history viewing and auditing

### Entity Features

[](#entity-features)

The `BizUser` entity includes comprehensive user data fields:

```
$user = new BizUser();
$user->setUsername('user@example.com');     // Required unique username
$user->setIdentity('unique_id');            // Optional external identifier
$user->setNickName('Display Name');         // User-friendly display name
$user->setEmail('user@example.com');        // Email address
$user->setMobile('13800138000');           // Mobile phone (Chinese format)
$user->setAvatar('avatar_url');            // Profile picture URL
$user->setType('admin');                   // User type/category
$user->setBirthday(new \DateTimeImmutable('1990-01-01'));
$user->setGender('male');
$user->setProvinceName('北京市');
$user->setCityName('北京市');
$user->setAreaName('朝阳区');
$user->setAddress('详细地址');
$user->setRemark('备注信息');
$user->setValid(true);                     // Enable/disable user
```

### Custom User Identity Resolution

[](#custom-user-identity-resolution)

Implement custom user identity resolution logic:

```
use BizUserBundle\Event\FindUserByIdentityEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class CustomUserIdentitySubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            FindUserByIdentityEvent::class => 'onFindUserByIdentity',
        ];
    }

    public function onFindUserByIdentity(FindUserByIdentityEvent $event): void
    {
        $identity = $event->getIdentity();

        // Custom logic: find by external ID
        if (preg_match('/^ext_(\d+)$/', $identity, $matches)) {
            $externalId = $matches[1];
            $user = $this->findUserByExternalId($externalId);
            if ($user) {
                $event->setUser($user);
            }
        }
    }
}
```

### Password Policy Customization

[](#password-policy-customization)

Configure password strength requirements:

```
// In your service configuration
services:
    BizUserBundle\Service\UserService:
        arguments:
            $passwordHistoryLimit: 10  # Check last 10 passwords
            $passwordMinLength: 12     # Require 12+ characters
```

### User Data Migration

[](#user-data-migration)

Merge user data when consolidating accounts:

```
use BizUserBundle\Service\UserService;

// Migrate all data from sourceUser to targetUser
$userService->migrate($sourceUser, $targetUser);

// This will:
// - Find all entities that reference sourceUser
// - Update them to reference targetUser instead
// - Handle the migration in a database transaction
```

### User Creation and Management

[](#user-creation-and-management)

```
use BizUserBundle\Service\UserService;

// Create a new user
$user = $userService->createUser('user@example.com', 'Display Name', 'avatar_url');

// Save the user
$userService->saveUser($user);

// Find multiple users by identity
$users = $userService->findUsersByIdentity('shared_identity');
```

Events
------

[](#events)

### FindUserByIdentityEvent

[](#finduserbyidentityevent)

Dispatched when finding a user by identity:

```
use BizUserBundle\Event\FindUserByIdentityEvent;

// Listen to the event
class UserIdentitySubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        return [
            FindUserByIdentityEvent::class => 'onFindUserByIdentity',
        ];
    }

    public function onFindUserByIdentity(FindUserByIdentityEvent $event)
    {
        $identity = $event->getIdentity();
        // Custom logic to find user
        $user = $this->customFindUser($identity);
        if ($user) {
            $event->setUser($user);
        }
    }
}
```

### FindUsersByIdentityEvent

[](#findusersbyidentityevent)

Dispatched when finding multiple users by identities:

```
use BizUserBundle\Event\FindUsersByIdentityEvent;

class BulkUserIdentitySubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            FindUsersByIdentityEvent::class => 'onFindUsersByIdentities',
        ];
    }

    public function onFindUsersByIdentities(FindUsersByIdentityEvent $event): void
    {
        $identities = $event->getIdentities();
        $users = $this->findUsersByCustomLogic($identities);
        $event->setUsers($users);
    }
}
```

Security
--------

[](#security)

### Password Requirements

[](#password-requirements)

The password strength validator requires passwords to contain at least 3 of the following:

- Uppercase letters
- Lowercase letters
- Numbers
- Special characters

Minimum length: 8 characters

### Password Security

[](#password-security)

- **History Tracking**: Prevents password reuse by tracking password history
- **Strength Validation**: Enforces strong password requirements
- **Secure Hashing**: Uses Symfony's password hasher for secure password storage

### User Security

[](#user-security)

- **Valid Flag**: Users can be disabled without deletion
- **Role-based Access**: Integration with role-based security systems
- **Audit Trail**: Track user creation and modification times

### Best Practices

[](#best-practices)

1. **Regular Password Updates**: Encourage users to update passwords regularly
2. **Account Monitoring**: Monitor for suspicious login activities
3. **Data Protection**: Ensure personal data is handled according to privacy regulations
4. **Access Controls**: Implement proper role-based access controls

### Security Considerations

[](#security-considerations)

- Always validate user input before processing
- Use HTTPS for all user authentication flows
- Implement rate limiting for login attempts
- Regularly audit user accounts and permissions
- Keep the bundle and its dependencies updated

Testing
-------

[](#testing)

Run the tests:

```
# Run all tests
./vendor/bin/phpunit packages/biz-user-bundle/tests

# Run with coverage
./vendor/bin/phpunit packages/biz-user-bundle/tests --coverage-html coverage

# Run specific test classes
./vendor/bin/phpunit packages/biz-user-bundle/tests/Controller/Admin/BizUserCrudControllerTest.php
./vendor/bin/phpunit packages/biz-user-bundle/tests/Service/UserServiceTest.php
```

License
-------

[](#license)

This bundle is released under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance64

Regular maintenance activity

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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 ~6 days

Total

4

Last Release

348d ago

### Community

Maintainers

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

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (2 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-biz-user-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-biz-user-bundle/health.svg)](https://phpackages.com/packages/tourze-biz-user-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

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