找不到EncryptPasswordPasswordHasher类:cakephp自定义密码haser

时间:2015-10-16 11:17:14

标签: php cakephp cakephp-2.5

我正在尝试创建自定义passwordHaser。我创建了如下文件。

EncryptPasswordPasswordHasher.php

App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');

class EncryptPasswordPasswordHasher extends AbstractPasswordHasher
{

    public function hash($password, $method = 'md5', $crop = true, $start = 4, $end = 10)
    {
        ...
    }

    public function check($password, $hashedPassword = null)
    {
        ...
    }
}

AdminController.php (配置组件)

App::uses('EncryptPasswordPasswordHasher ', 'Controller/Component/Auth');

public $components = [
        'Auth' => [
            'authenticate'   => [
                'Form' => [
                    'userModel' => 'Admin',
                    'fields'    => [
                        'username' => 'username',
                        'password' => 'password'
                    ],
                    'passwordHasher' => [
                        'className' => 'EncryptPassword'
                    ]
                ]
            ],
            'loginAction'    => [
                'controller' => '',
                'action'     => 'login'
            ],
            'logoutRedirect' => [
                'controller' => '',
                'action'     => 'login'
            ],
            'loginRedirect'  => [
                'controller' => '',
                'action'     => 'dashboard'
            ]
        ]
    ];

admin.php的 (AdminModel)

App::uses('EncryptPasswordPasswordHasher ', 'Controller/Component/Auth');

public function beforeSave($options = array()) {
        if (!empty($this->data[$this->alias]['password'])) {
            $passwordHasher = new EncryptPasswordPasswordHasher();
            $this->data[$this->alias]['password'] = $passwordHasher->hash(
                $this->data[$this->alias]['password']
            );
        }
        return true;
    }

我想使用自己的密码加密,我在app / Controller / Component / Auth文件夹中创建了这个EncryptPasswordPasswordHasher。但这不是完美的。它给出了致命错误。

错误:找不到类'EncryptPasswordPasswordHasher'

我已经在谷歌搜索此问题,但我找不到任何正确的解决方案。没有文章有正确的指示来使用我们的自定义PasswordHaser。

请帮助我解决这个问题。 感谢。

0 个答案:

没有答案