2017 © Pedro Peláez
 

yii2-extension yii2-password-behavior

Behavior for change and create password of user account.

image

bupy7/yii2-password-behavior

Behavior for change and create password of user account.

  • Monday, October 19, 2015
  • by bupy7
  • Repository
  • 1 Watchers
  • 4 Stars
  • 2,868 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 16 % Grown

The README.md

yii2-password-behavior

Behavior for change and create password of user account., (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

php composer.phar require --prefer-dist bupy7/yii2-password-behavior "*"

or add, (*4)

"bupy7/yii2-password-behavior": "*"

to the require section of your composer.json file., (*5)

Usage

Implement your user identity model with bupy7\password\PasswordInterface and add following code:, (*6)

use Yii;

/**
 * @inheritdoc
 */
public function validatePassword($password)
{
    return Yii::$app->security->validatePassword($password, $this->password);
}

/**
 * @inheritdoc
 */
public function setPassword($password)
{
    $this->password = Yii::$app->security->generatePasswordHash($password);
}

Added following properties to your model:, (*7)

public $old_password;
public $new_password;
public $confirmed_password;

Attach behavior to model in your controller:, (*8)

use bupy7\password\PasswordBehavior;

$model->attachBehavior('passwordBehavior', [
    'class' => PasswordBehavior::className(),
    // other configurations
]);

If you want set password with checking old password

In your controller:, (*9)

use bupy7\password\PasswordBehavior;

$model->attachBehavior('passwordBehavior', [
    'class' => PasswordBehavior::className(),
    'skipOnEmpty' => true,
    'checkPassword' => true,
    'scenarios' => [$model->scenario],
]);

If you want set new password without checking old password

In your controller:, (*10)

use bupy7\password\PasswordBehavior;

$model->attachBehavior('passwordBehavior', [
    'class' => PasswordBehavior::className(),
    'skipOnEmpty' => true,
    'checkPassword' => false,
    'scenarios' => [$model->scenario],
]);

If password must be set (example, registration)

use bupy7\password\PasswordBehavior;

$model->attachBehavior('passwordBehavior', [
    'class' => PasswordBehavior::className(),
    'skipOnEmpty' => false,
    'checkPassword' => false,
    'scenarios' => [$model->scenario],
]);

License

yii2-password-behavior is released under the BSD 3-Clause License., (*11)

The Versions

19/10 2015

dev-master

9999999-dev

Behavior for change and create password of user account.

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 password behavior

19/10 2015

1.0.1

1.0.1.0

Behavior for change and create password of user account.

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 password behavior

10/10 2015

1.0.0

1.0.0.0

Behavior for change and create password of user account.

  Sources   Download

BSD-3-Clause

The Requires

 

extension yii2 password behavior