CakePHP 3.x授权(标识)在新服务器上失败

时间:2018-01-19 21:24:57

标签: cakephp authorization cakephp-3.0

我有一个本地环境(Mac OSX - PHP7.1),我有一个用户和密码。 当我使用DefaultPasswordHasher()保存它时,它在数据库中进行哈希处理。 我也可以登录!

但现在我将我的项目移动到在线服务器(Ubuntu + PHP 7.1)。安全盐保持不变。我也可以使用同一个用户登录。 但是当我更改用户的密码时 - 它会一直说密码不正确。

密码在在线数据库中进行哈希处理。

当我在本地环境中编辑密码并将MySQL行复制到我的在线版本时 - 我可以再次登录。发生了什么事?

UserController.php

if ($this->request->is(['post', 'put'])) {

        $user = $this->Users->patchEntity($user, $this->request->data);
        if ($this->Users->save($user)) {

            $this->Auth->setUser($user->toArray());
            return $this->redirect($this->Auth->redirectUrl());

        }else{
            $this->set('error','Wachtwoorden zijn niet gelijk');
        }
}

实体/ user.php的

protected $_accessible = ['*' => true];

protected function _setPassword($password) {
    return (new DefaultPasswordHasher)->hash($password);
}

模型/ UsersTable.php

public function beforeSave( Event $event ) {
    $entity = $event->data['entity'];

    //existing user and password fields are set
    if(isset($entity->id) && isset($entity->password) && isset($entity->password_repeat) && !empty($entity->password) && !empty($entity->password_repeat)) {
        /* THIS SEEMS TO BE THE PROBLEM - AFTER REMOVING THIS THE PROBLEM WAS SOLVED */
        $passwordHahsher  = new DefaultPasswordHasher();
        $entity->password = $passwordHahsher->hash( $entity->password);

    }

    // add hash for unique profile-page
    if(!isset($entity->id)){
        $entity->hash = sha1(date('dmyhis'));
    }

}

0 个答案:

没有答案