PHPackages                             pjhl/yii2-pwstrength - 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. pjhl/yii2-pwstrength

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

pjhl/yii2-pwstrength
====================

This extension provides a simple password validator for Yii Framework 2.0.

1.0.1(9y ago)180MITJavaScriptPHP &gt;=5.4.0

Since Jul 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/pjhl/yii2-pwstrength)[ Packagist](https://packagist.org/packages/pjhl/yii2-pwstrength)[ Docs](https://github.com/pjhl/yii2-pwstrength)[ RSS](/packages/pjhl-yii2-pwstrength/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (3)Used By (0)

yii2-pwstrength
===============

[](#yii2-pwstrength)

This extension provides a simple password validator for Yii Framework 2.0.

DEMO
----

[](#demo)

TODO: Make demo.

INSTALLATION
------------

[](#installation)

Install the extension through [composer](http://getcomposer.org/download/):

```
php composer.phar require pjhl/yii2-pwstrength:~1.0
```

or add this line to the require section of your `composer.json` file:

```
"pjhl/yii2-pwstrength": "^1.0"

```

USAGE
-----

[](#usage)

### 1. Add this in your model:

[](#1-add-this-in-your-model)

```
use pjhl\pwstrength\StrengthValidator;

// use the validator in your model rules
public function rules() {
    return [
        [['username', 'password'], 'required'],
        [['password'], StrengthValidator::className()]
    ];
}
```

### 2. Update your view file:

[](#2-update-your-view-file)

Optional template:

```

```

```

            The password is too simple, must be at least 6 characters

```

### 3. Add the JS listener (POS\_READY):

[](#3-add-the-js-listener-pos_ready)

```
jQuery(function(){
    // Listen
    $('#loginform-password').on('strengthChange', function(e, data){
        var passStrength = $('#strength');
        var len = data.value.length;

        var label = '';
        var labelType = '';
        if (data.error) {
            label = data.error;
            labelType = 'danger';
        } else {
            if (len
