定制 bupy7/yii2-password-behavior 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bupy7/yii2-password-behavior

最新稳定版本:1.0.1

Composer 安装命令:

composer require bupy7/yii2-password-behavior

包简介

Behavior for change and create password of user account.

README 文档

README

Behavior for change and create password of user account.

Installation

The preferred way to install this extension is through composer.

Either run

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

or add

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

to the require section of your composer.json file.

Usage

Implement your user identity model with bupy7\password\PasswordInterface and add following code:

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:

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

Attach behavior to model in your controller:

use bupy7\password\PasswordBehavior;

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

If you want set password with checking old password

In your controller:

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:

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.

统计信息

  • 总下载量: 8.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2015-10-08