PHPackages                             vocjunior/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. [Security](/categories/security)
4. /
5. vocjunior/password-policy

Abandoned → [git@github.com:martinssipenko/password-policy.git](/?search=git%40github.com%3Amartinssipenko%2Fpassword-policy.git)Library[Security](/categories/security)

vocjunior/password-policy
=========================

A tool for managing password policies

061PHP

Since Sep 12Pushed 11y ago1 watchersCompare

[ Source](https://github.com/vocjunior/password-policy)[ Packagist](https://packagist.org/packages/vocjunior/password-policy)[ RSS](/packages/vocjunior-password-policy/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

PasswordPolicy
==============

[](#passwordpolicy)

A tool for checking and creating password policies in PHP and JS.

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

[](#installation)

Use composer to setup an autoloader

```
php composer.phar install

```

Require the composer autoload file:

```
require_once 'vendor/autoload.php';

```

Usage:
------

[](#usage)

To use, first instantiate the core policy object:

```
$policy = new \PasswordPolicy\Policy;

```

Then, add rules:

```
$policy->contains('lowercase', $policy->atLeast(2));

```

### Supported rule helper methods are:

[](#supported-rule-helper-methods-are)

- `contains($class, $constraint = null, $description = '')`: Checks to see if a password contains a class of chars

    Supported Short-Cut classes:

    - `letter` - `a-zA-Z`
    - `lowercase` - `a-z`
    - `uppercase` - `A-Z`
    - `digit` - `0-9`
    - `symbol` - `^a-zA-Z0-9` (in other words, non-alpha-numeric)
    - `null` - `\0`
    - `alnum` - `a-zA-Z0-9`

    The second param is a constraint (optional)
- `length($constraint)`: Checks the length of the password matches a constraint
- `endsWith($class, $description = '')`: Checks to see if the password ends with a character class.
- `startsWith($class, $description = '')`: Checks to see if the password starts with a character class.
- `notMatch($regex, $description)`: Checks if the password does not match a regex.
- `match($regex, $description)`: Checks if the password matches the regex.

### Supported Constraints:

[](#supported-constraints)

The policy also has short-cut helpers for creating constraints:

- `atLeast($n)`: At least the param matches

    Equivilant to `between($n, PHP_INT_MAX)`
- `atMost($n)`: At most the param matches

    Equivilant to `between(0, $n)`
- `between($min, $max)`: Between $min and $max number of matches
- `never()`: No matches

    Equivilant to `between(0, 0)`

Testing the policy
------------------

[](#testing-the-policy)

Once you setup the policy, you can then test it in PHP using the `test($password)` method.

```
$result = $policy->test($password);

```

The result return is a stdclass object with two members, result and messages.

- `$result->result` - A boolean if the password is valid.
- `$result->messages` - An array of messages

Each message is an object of two members:

- `$message->result` - A boolean indicating if the rule passed
- `$message->message` - A textual description of the rule

Using JavaScript
----------------

[](#using-javascript)

Once you've built the policy, you can call `toJavaScript()` to generate a JS anonymous function for injecting into JS code.

```
$js = $policy->toJavaScript();
echo "var policy = $js;";

```

Then, the policy object in JS is basically a wrapper for `$policy->test($password)`, and behaves the same (same return values).

```
var result = policy(password);
if (!result.result) {
    /* Process Messages To Display Failure To User */
}

```

One note for the JavaScript, any regular expressions that you write need to be deliminated by `/` and be valid JS regexes (no PREG specific functionality is allowed).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% 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/0fbc62909d7c404c0ac2d74357091abf36fe1677210581bb1dd8c5b7e5959bf4?d=identicon)[martinssipenko](/maintainers/martinssipenko)

---

Top Contributors

[![ircmaxell](https://avatars.githubusercontent.com/u/660654?v=4)](https://github.com/ircmaxell "ircmaxell (4 commits)")[![radmen](https://avatars.githubusercontent.com/u/1190255?v=4)](https://github.com/radmen "radmen (1 commits)")[![vocjunior](https://avatars.githubusercontent.com/u/8618094?v=4)](https://github.com/vocjunior "vocjunior (1 commits)")

### Embed Badge

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

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

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M212](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M112](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

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