PHP code example of bupy7 / yii2-password-behavior

1. Go to this page and download the library: Download bupy7/yii2-password-behavior library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bupy7 / yii2-password-behavior example snippets


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);
}

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

use bupy7\password\PasswordBehavior;

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

use bupy7\password\PasswordBehavior;

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

use bupy7\password\PasswordBehavior;

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

use bupy7\password\PasswordBehavior;

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

php composer.phar