2017 © Pedro Peláez
 

yii2-extension yii2-pwstrength

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

image

pjhl/yii2-pwstrength

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

  • Thursday, August 4, 2016
  • by pjhl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 66 Installations
  • JavaScript
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

yii2-pwstrength

This extension provides a simple password validator for Yii Framework 2.0., (*1)

DEMO

TODO: Make demo., (*2)

INSTALLATION

Install the extension through composer:, (*3)

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

or add this line to the require section of your composer.json file:, (*4)

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

USAGE

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:

Optional template:, (*5)

<?= $form->field($model, 'password', [
    "template" => "{input}"
])->passwordInput() ?>
<div id="strength" class="row" style="display: none;">
    <div class="col-xs-12">
        <div class="progress">
            <div class="progress-bar progress-bar-danger" style="width:1%;"></div>
        </div>
        <div class="progress-label text-danger">
            The password is too simple, must be at least 6 characters
        </div>
    </div>
</div>

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<6) {
                label = 'The password is too simple, must be at least 6 characters';
                labelType = 'danger';
            } else {
                switch (data.strength) {
                    case 'low':
                        label = 'The password is too simple';
                        labelType = 'danger';
                        break;
                    case 'middle':
                        label = 'A middle password';
                        labelType = 'warning';
                        break;
                    case 'strong':
                        label = 'A strong password';
                        labelType = 'success';
                        break;
                }
            }
        }

        passStrength.find('.progress-bar')
            .removeClass('progress-bar-danger progress-bar-warning progress-bar-success')
            .addClass('progress-bar-'+labelType)
            .width(data.percent+'%');
        passStrength.find('.progress-label')
            .removeClass('text-danger text-warning text-success')
            .addClass('text-'+labelType)
            .text(label);
        passStrength.show();
    });
});

LICENSE

MIT, (*6)

The Versions

04/08 2016

dev-master

9999999-dev https://github.com/pjhl/yii2-pwstrength

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

yii2 validator validation password strength

04/08 2016

1.0.1

1.0.1.0 https://github.com/pjhl/yii2-pwstrength

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

yii2 validator validation password strength

14/07 2016

1.0.0

1.0.0.0 https://github.com/pjhl/yii2-pwstrength

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

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

yii2 validator validation password strength