CakePHP 3:Auth-> identify()总是在没有检查密码的情况下使用有效的用户名

问题描述 投票:1回答:1

Auth-> identify始终允许有效的用户名登录而不检查密码。我只需要一个有效的用户名,我就可以轻松打开仪表板。当我将login.ctp中的输入密码名称从密码更改为password2时,我无法再登录了。这是我昨天面临的一个奇怪的问题,但没有弄清楚如何解决它。

这是app.php

$this->loadComponent('Auth',['loginRedirect'=>['controller'=>'Dashboard','action'=>'index'],
                                     'logoutRedirect'=>['controller'=>'Users',"action"=>"login"],
                                     'authorize' => array('Controller')
                                    ]);

这是我的登录视图:

<form class="login-form" method="post"> 
    <input type="text" placeholder="<?php echo __("Username");?>" name="username" />
    <input type="password" placeholder="<?php echo __("Password");?>" name="password"/>
    <button id="btn_login"><?php echo __("Login");?></button>
</form>

UsersController中的我的登录功能:

public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);
            return $this->redirect($this->Auth->redirectUrl());
        } else {
            $this->Flash->error(__('Username or password is incorrect'));
        }
    }
}

最后可能是混乱,旧的开发人员为用户创建了一个名为app_members的表。数据库中没有名为users的表,因此他编写了以下内容:

在模型/实体中,user.php和appMember都包含:

<?php
namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
class User (or AppMember) extends Entity
{
    protected $_accessible = ['*'=> true,'id' => false];
    protected function _setPassword($password)
    {
        return (new DefaultPasswordHasher)->hash($password);
    }
}
?>

对于model / table / UsersTable.php,他从appMember扩展:

<?php 
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
class UsersTable extends Table
{

    public function initialize(array $config)
    {
      $this->table('app_member');
    }
    public function validationDefault(Validator $validator)
    {
        return $validator
            ->notEmpty('username', 'A username is required')
            ->notEmpty('password', 'A password is required')
            ->notEmpty('role', 'A role is required');            
    }
}

编辑1:app.php isAuthorized函数:

public function isAuthorized($users)
    {
        if(isset($users))
        {
            return true;
        }
        else{
            return false;
        }
    }
php mysql authentication cakephp cakephp-3.0
1个回答
0
投票

花了很多时间寻找问题后。我发现有人修改了CakePHP src / Auth / Base Authenticate.php并对此进行了评论:

/*if (!$hasher->check($password, $hashedPassword)) {
                return false;
            }*/

扑克脸

© www.soinside.com 2019 - 2024. All rights reserved.