本文整理汇总了PHP中app\modules\user\models\User::hashPassword方法的典型用法代码示例。如果您正苦于以下问题:PHP User::hashPassword方法的具体用法?PHP User::hashPassword怎么用?PHP User::hashPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\modules\user\models\User
的用法示例。
在下文中一共展示了User::hashPassword方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changePassword
/**
* @return bool
*/
public function changePassword()
{
if (!$this->validate()) {
return false;
}
$user = User::findIdentity(\Yii::$app->user->identity->getId());
$user->password_hash = User::hashPassword($this->new_password);
$user->save();
return true;
}
示例2: generatePasswordResetToken
/**
* @return bool
*/
public function generatePasswordResetToken()
{
if (!$this->validate()) {
return false;
}
$new_password = \Yii::$app->security->generateRandomString(8);
/** @var User $user */
$user = User::findOne(['email' => $this->email]);
$user->password_reset_token = User::generatePasswordResetToken();
$user->password_hash = User::hashPassword($new_password);
$user->status = User::USER_STATUS_INACTIVE;
$user->save();
$isSend = \Yii::$app->mailer->compose('user/forgot_password', ['user_name' => $user->name, 'token' => $user->password_reset_token, 'new_password' => $new_password])->setFrom(Settings::value('general', 'shopEmail'))->setTo($this->email)->setSubject(\Yii::t('mail', 'New password activation'))->send();
if (!$isSend) {
$this->addError(\Yii::t('mail', 'Oops, can\'t deliver letter to such email address.'));
}
return $isSend;
}
示例3: register
/**
* @throws \yii\base\Exception
* @throws \yii\base\InvalidConfigException
*/
public function register()
{
if (!$this->validate()) {
return false;
}
$user = new User();
$user->email = $this->email;
$user->name = $this->name;
$user->country_id = $this->country_id;
$user->phone = $this->phone;
$user->address = $this->address;
$user->password_hash = User::hashPassword($this->password);
$user->generateAuthKey();
$user->status = User::USER_STATUS_ACTIVE;
$user->save();
return User::login($this->email, true);
}