PHPackages                             olssonm/l5-zxcvbn - 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. olssonm/l5-zxcvbn

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

olssonm/l5-zxcvbn
=================

Implementation of the zxcvbn project by @dropbox for Laravel. Uses zxcvbn-php by @bjeavons.

v6.0(2mo ago)28311.1k—6.7%121MITPHPPHP ^8.2CI passing

Since Oct 16Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/olssonm/laravel-zxcvbn)[ Packagist](https://packagist.org/packages/olssonm/l5-zxcvbn)[ Docs](https://github.com/olssonm/laravel-zxcvbn)[ Fund](https://marcusolsson.me/kontakta)[ GitHub Sponsors](https://github.com/olssonm)[ RSS](/packages/olssonm-l5-zxcvbn/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (10)Versions (26)Used By (1)

Zxcvbn for Laravel
==================

[](#zxcvbn-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/9ba62da35adab44212f494d3e23c3c1f71e05d564d0f0f1b4b7971c3af877fd5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6c73736f6e6d2f6c352d7a786376626e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olssonm/l5-zxcvbn)[![Total downloads](https://camo.githubusercontent.com/4bca4d4f1eaf70ee5054f47da30699962a36cfd4b5628dd92ccbea25ca6158d1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6c73736f6e6d2f6c352d7a786376626e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olssonm/l5-zxcvbn)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/aeb9c8364791c26922704e9dec4a4d362512897af5c44a96da9c1d1a47392b0a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6f6c73736f6e6d2f6c61726176656c2d7a786376626e2f746573742e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/olssonm/ampersand/actions/workflows/test.yml)

[![zxcvbn](https://user-images.githubusercontent.com/907114/41193108-747d9b50-6c08-11e8-8f9c-57874f52fa9b.png)](https://user-images.githubusercontent.com/907114/41193108-747d9b50-6c08-11e8-8f9c-57874f52fa9b.png)

A simple implementation of zxcvbn for Laravel. This package allows you to access "zxcvbn-related" data on a passphrase in the application and also to use zxcvbn as a standard validator.

Uses [Zxcvbn-PHP](https://github.com/bjeavons/zxcvbn-php) by [@bjeavons](https://github.com/bjeavons), which in turn is inspired by [zxcvbn](https://github.com/dropbox/zxcvbn) by [@dropbox](https://github.com/dropbox).

Install
-------

[](#install)

Via Composer

```
$ composer require olssonm/l5-zxcvbn
```

If you wish to have the ability to use `Zxcvbn` via dependency injection, or just have a quick way to access the class – add an alias to the facades:

```
'aliases' => [
    'Zxcvbn' => Olssonm\Zxcvbn\Facades\Zxcvbn::class
]
```

Usage
-----

[](#usage)

If you've added `Olssonm\Zxcvbn` as an alias, your can access Zxcvbn easily from anywhere in your application:

### "In app"

[](#in-app)

```
use Zxcvbn;

class MyClass extends MyOtherClass
{
    public function myFunction()
    {
        $zxcvbn = Zxcvbn::passwordStrength('password');
        dd($zxcvbn);

        // array:9 [
        //     "password" => "password"
        //     "guesses" => 3.0
        //     "guesses_log10" => 0.47712125471966
        //     "sequence" => [],
        //     "crack_times_seconds" => array:4 [
        //         "online_throttling_100_per_hour" => 108.0
        //         "online_no_throttling_10_per_second" => 0.3
        //         "offline_slow_hashing_1e4_per_second" => 0.0003
        //         "offline_fast_hashing_1e10_per_second" => 3.0E-10
        //     ]
        //     "crack_times_display" => array:4 [
        //         "online_throttling_100_per_hour" => "2 minutes"
        //         "online_no_throttling_10_per_second" => "less than a second"
        //         "offline_slow_hashing_1e4_per_second" => "less than a second"
        //         "offline_fast_hashing_1e10_per_second" => "less than a second"
        //     ]
        //     "score" => 0
        //     "feedback" => array:2 [
        //         "warning" => "This is a top-10 common password"
        //         "suggestions" => array:1 [
        //         0 => "Add another word or two. Uncommon words are better."
        //         ]
        //     ]
        //     "calc_time" => 0.020488977432251
        // ]
    }
}
```

Play around with different passwords and phrases, the results may surprise you. Check out [Zxcvbn-PHP](https://github.com/bjeavons/zxcvbn-php) for more uses and examples.

### As a validator

[](#as-a-validator)

The package makes two types of validations available for your application. `zxcvbn` and `zxcvbn_dictionary`.

### zxcvbn

[](#zxcvbn)

With this rule you set the lowest score that the phrase need to score wuth Zxcvbn to pass.

**Syntax**

```
'input' => 'zxcvbn:min_value'
```

**Examples**

```
$request->validate([
    'password' => 'required|zxcvbn:3'
]);
```

You may also initialize the rule as an object:

```
use Olssonm\Zxcvbn\Rules\Zxcvbn;

function rules()
{
    return [
        'password' => ['required', new Zxcvbn($minScore = 3)]
    ];
}
```

In this example the password should at least have a "score" of three (3) to pass the validation. Of course, you should probably use the [zxcvbn-library](https://github.com/dropbox/zxcvbn) on the front-end too to allow the user to know this before posting the form.

### zxcvbn\_dictionary

[](#zxcvbn_dictionary)

This is a bit more interesting. `zxcvbn_dictionary` allows you to input both the users username and/or email together with their password (you need suply one piece of user input). The validator checks that the password doesn't exist in the username, or that they are too similar.

**Syntax**

```
'input' => 'zxcvbn_dictionary:input1,input2'
```

**Examples**

```
$request->validate([
    'password' => sprintf('required|zxcvbn_dictionary:%s,%s', $request->username, $request->email)
]);
```

```
use Olssonm\Zxcvbn\Rules\ZxcvbnDictionary;

function rules()
{
    return [
        'password' => ['required', new ZxcvbnDictionary($this->username)]
    ];
}
```

Testing
-------

[](#testing)

```
$ composer test
```

or

```
$ phpunit
```

License
-------

[](#license)

The MIT License (MIT). Please see the [License File](LICENSE.md) for more information.

© 2022 [Marcus Olsson](https://marcusolsson.me).

###  Health Score

65

—

FairBetter than 99% of packages

Maintenance88

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

 Bus Factor1

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

###  Release Activity

Cadence

Every ~200 days

Recently: every ~322 days

Total

20

Last Release

60d ago

Major Versions

v1.0 → v2.02016-11-07

v2.2 → v3.02017-11-09

v3.3 → v4.02019-06-20

v4.5 → 5.x-dev2022-09-08

v5.3 → v6.02026-03-19

PHP version history (8 changes)v1.0PHP &gt;=5.3.0

v2.2PHP &gt;=5.6.0

v3.0PHP &gt;=5.6.0|&gt;=7.0

v3.3PHP &gt;=7.1.3

v4.1PHP ^7.1

v4.4PHP ^7.3|^8.0

5.x-devPHP ^7.4|^8.0

v6.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/74a309aadadeae81baef2394d37375673d03f11133b28a831a30825361d1d68c?d=identicon)[olssonm](/maintainers/olssonm)

---

Top Contributors

[![olssonm](https://avatars.githubusercontent.com/u/907114?v=4)](https://github.com/olssonm "olssonm (49 commits)")[![AnnoyingTechnology](https://avatars.githubusercontent.com/u/5336824?v=4)](https://github.com/AnnoyingTechnology "AnnoyingTechnology (2 commits)")[![bubenkoff](https://avatars.githubusercontent.com/u/427136?v=4)](https://github.com/bubenkoff "bubenkoff (1 commits)")[![Claw666](https://avatars.githubusercontent.com/u/11250747?v=4)](https://github.com/Claw666 "Claw666 (1 commits)")[![kblais](https://avatars.githubusercontent.com/u/1931954?v=4)](https://github.com/kblais "kblais (1 commits)")

---

Tags

laravellaravel-5-packagevalidationzxcvbnlaravelvalidationsecurityzxcvbnpasswordsolssonmstaple horse battery

###  Code Quality

TestsPest

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/olssonm-l5-zxcvbn/health.svg)

```
[![Health](https://phpackages.com/badges/olssonm-l5-zxcvbn/health.svg)](https://phpackages.com/packages/olssonm-l5-zxcvbn)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[rebelinblue/laravel-zxcvbn

Service provider to use the zxcvbn project by @dropbox in Laravel 5.4 and above

1160.4k](/packages/rebelinblue-laravel-zxcvbn)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)

PHPackages © 2026

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