PHPackages                             joshralph/password-policy - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. joshralph/password-policy

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

joshralph/password-policy
=========================

A library to intuitively create password policies and validate a subject against them.

0.3.0(5y ago)15390.4k↓32.5%6[5 issues](https://github.com/joshralph93/password-policy/issues)[1 PRs](https://github.com/joshralph93/password-policy/pulls)PHPPHP &gt;=5.5

Since Oct 25Pushed 5y ago2 watchersCompare

[ Source](https://github.com/joshralph93/password-policy)[ Packagist](https://packagist.org/packages/joshralph/password-policy)[ RSS](/packages/joshralph-password-policy/feed)WikiDiscussions master Synced 2d ago

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

[![Build Status](https://camo.githubusercontent.com/aa24e18b60e8b5ae60fb2f57c8e2641169bdcd65a626c648a3fa6761458ac19f/68747470733a2f2f6170692e7472617669732d63692e6f72672f6a6f736872616c706839332f70617373776f72642d706f6c6963792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/joshralph93/password-policy)

A fluent password policy builder library. The package can be used stand-alone or easily added to Laravel.

Table of Contents
=================

[](#table-of-contents)

- [Install](#install)
- [Stand Alone Usage](#policy-builder)
- [Laravel](#larave)
    - [Install](#install-package)
    - [Define Policies](#define-policies)
    - [Setup Validation](#setup-validation)

Install
-------

[](#install)

```
$ composer require joshralph/password-policy

```

Usage
-----

[](#usage)

### Policy Builder

[](#policy-builder)

```
$builder = new \PasswordPolicy\PolicyBuilder(new \PasswordPolicy\Policy);
$builder->minLength(6)
    ->upperCase();
```

Any of the following methods may be chained on the builder class to build your password policy.

#### minLength(length)

[](#minlengthlength)

##### length

[](#length)

Type: int

Minimum number of characters the password must contain.

#### maxLength(length)

[](#maxlengthlength)

##### length

[](#length-1)

Type: int

Maximum number of characters the password must contain.

#### upperCase(\[min\])

[](#uppercasemin)

##### min

[](#min)

Type: int

Minimum number of upper case characters the password must contain.

#### lowerCase(\[min\])

[](#lowercasemin)

##### min

[](#min-1)

Type: int

Minimum number of lower case characters the password must contain.

#### digits(\[min\])

[](#digitsmin)

##### min

[](#min-2)

Type: int

Minimum number of numeric characters the password must contain.

#### specialCharacters(\[min\])

[](#specialcharactersmin)

##### min

[](#min-3)

Type: int

Minimum number of special characters the password must contain.

#### doesNotContain(phrases \[,phrases\])

[](#doesnotcontainphrases-phrases)

##### phrases

[](#phrases)

Type: string|array

Phrases that the password should not contain

*Example*

```
->doesNotContain('password', $firstName, $lastName)
```

#### minPassingRules(passesRequired, ruleSet)

[](#minpassingrulespassesrequired-ruleset)

##### passesRequired

[](#passesrequired)

Type: int

The minimum number of rules in the *ruleSet* that need to pass, in order for this rule to pass

##### ruleSet

[](#ruleset)

Type: \\Closure

A closure which is given a new PolicyBuilder instance.

*Example*

```
// One of these rules must pass
->minPassingRules(1, function (PolicyBuilder $builder) {
    $builder->doesNotContain('password')
        ->minLength(10);
})
```

### Laravel

[](#laravel)

If you are a Laravel user, this package can seamlessly integrate with your validators.

#### Install Package

[](#install-package)

Begin by adding the below service provider.

```
// config/app.php

'providers' => [
    // ...
    \PasswordPolicy\Providers\Laravel\PasswordPolicyServiceProvider::class,
],
```

#### Define Policies

[](#define-policies)

Within an app service provider (e.g. AppServiceProvider.php) you can start defining password policies.

```
// App/Providers/AppServiceProvider.php

// use PasswordPolicy\PolicyBuilder;

/**
 * Bootstrap any application services.
 *
 * @return void
 */
public function boot()
{
    \PasswordPolicy::define('default', function (PolicyBuilder $builder) {
        $builder->minLength(8)
            ->upperCase(3);
            // ...
    });
}
```

You can define as many policies as you require, however it's recommended to stick with 'default' when possible.

#### Setup Validation

[](#setup-validation)

Once you're policies have been defined, you're ready to start using the policies. A new 'password' validation rule is now available to use.

```
// Request class

/**
 * Declare validation rules
 *
 * @return array
 */
public function rules()
{
    return [
        // ...
        'password' => 'required|password'
    ];
}
```

The validator will use the 'default' policy by default. To use an alternative policy, add an additional parameter:

```
'password' => 'required|password:admin'
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 78.3% 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 ~528 days

Total

3

Last Release

2116d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8427353?v=4)[joshralph93](/maintainers/joshralph93)[@joshralph93](https://github.com/joshralph93)

---

Top Contributors

[![nmjosh](https://avatars.githubusercontent.com/u/43368937?v=4)](https://github.com/nmjosh "nmjosh (18 commits)")[![joshralph93](https://avatars.githubusercontent.com/u/8427353?v=4)](https://github.com/joshralph93 "joshralph93 (4 commits)")[![vlad-barjovanu](https://avatars.githubusercontent.com/u/3929595?v=4)](https://github.com/vlad-barjovanu "vlad-barjovanu (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/joshralph-password-policy/health.svg)

```
[![Health](https://phpackages.com/badges/joshralph-password-policy/health.svg)](https://phpackages.com/packages/joshralph-password-policy)
```

###  Alternatives

[marcosh/php-validation-dsl

A DSL for validating data in a functional fashion

483.9k](/packages/marcosh-php-validation-dsl)

PHPackages © 2026

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