-1
由於一些奇怪的原因,我發現很難用yii-> $ app-> generatePasswordhash($ password。)登錄。我有一個註冊用戶並更改密碼的備份。用戶可以在我創建它們時成功登錄,但是當我編輯用戶密碼時,系統會一直告訴我無效的用戶名或密碼。以下是我的代碼。yii generatepasswordhash不工作
//Model
Class Adminuser extends ActiveRecord
{
public $resetpassword
public function activateuser($id,$newpassword)
{
//echo Yii::$app->security->generatePasswordHash($newpassword); exit;
$user = Adminuser::find()->where(['id' =>$id])->one();
$user->status = self::SET_STATUS;
$user->password_reset_token = null;
$user->password = Admin::genPassword($this->resetpassword); // this returns yii::$app->security->generatePasswordHash($password)
return $user->save();
}
}
//控制器動作
public function actionActivate($id)
{
$model = new Adminuser();
$model->scenario = 'adminactivate';
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if($model->activateuser($id,$model->password))
{
//send a mail
Yii::$app->session->setFlash('success', 'New user has been activated.');
return $this->redirect(['index']);
}
else
$errors = $model->errors;
}
return $this->render('activate', [
'model' => $model,
]);
}
請我需要幫助
謝謝。現在嘗試它並恢復 – codeDev