1

I am trying to create a custom passwordHaser. I have create files like below.

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 (configure component)

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;
    }

I want to use my own password encryption for this I have create this EncryptPasswordPasswordHasher in app/Controller/Component/Auth folder. but this is not works perfect. It give below fatal error.

Error: Class 'EncryptPasswordPasswordHasher' not found

I have already search in google for this issue, but i don't find any proper solution. No articles is there who have a proper instruction to use the our custom PasswordHaser.

Please help me in this concern. Thanks.

Rav's Patel
  • 743
  • 6
  • 22
  • i think, it's here `'passwordHasher' => [ 'className' =>'EncryptPasswordPasswordHasher']` – Insane Skull Oct 16 '15 at 11:20
  • No, Still it's not working... – Rav's Patel Oct 16 '15 at 11:30
  • No, cakephp don't have EncryptPasswordPasswordHasher class. I have create EncryptPasswordPasswordHasher class for the custom password encryption. See in my above example. EncryptPasswordPasswordHasher.php file contains EncryptPasswordPasswordHasher class – Rav's Patel Oct 16 '15 at 11:46
  • please give the directory where you have added class EncryptPasswordPasswordHasher.php – Alimon Karim Oct 16 '15 at 12:10
  • In 'app/Controller/Component/Auth' this directory i have added my EncryptPasswordPasswordHasher.php – Rav's Patel Oct 16 '15 at 12:15
  • 2
    In your `App::uses()` calls, there's a whitespace after `EncryptPasswordPasswordHasher`. – ndm Oct 16 '15 at 16:16
  • Yes, you are right brother. That's the problem. Just remove the space after the EncryptPasswordPasswordHashe in App::users() and its works perfect. Thanks for the help all of you. – Rav's Patel Oct 17 '15 at 06:55

0 Answers0