PHP code example of antonyz89 / yii2-password-behavior
1. Go to this page and download the library: Download antonyz89/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/ */
antonyz89 / yii2-password-behavior example snippets
public function behaviors()
{
return [
PasswordBehavior::class,
];
}
/**
* @property string $password
*/
class ExampleModel extends ActiveRecord implements IdentityInterface, UserCredentialsInterface {
public $new_password, $confirmPsw, $oldPsw, $authorizationKey;
// new_password can be skipped because they already exists
/**
* @inheritDoc
*/
public function behaviors()
{
return [
[
'class' => PasswordBehavior::class,
'password_hash' => 'password',
'confirm_password' => 'confirmPsw',
'auth_key' => 'authorizationKey',
'old_password' => 'oldPsw'
]
];
}
}
/**
* @property string $password
*/
class ExampleModel extends ActiveRecord implements IdentityInterface, UserCredentialsInterface {
public $new_password;
// new_password can be skipped because they already exists
/**
* @inheritDoc
*/
public function behaviors()
{
return [
[
'class' => PasswordBehavior::class,
'password_hash' => 'password',
/*
* Will be ignored and comparison between
* `$confirm_password` and `$new_password` or `$password_hash` will not happen
*/
'confirm_password' => false,
/*
* Will be ignored and comparison between
* `old_password` and `$new_password` will not happen
*/
'old_password' => false,
/*
* Will be ignored and when a new password is defined
* a new Authorization Key will not generated
*/
'auth_key' => false
]
];
}
}