0
votes

i have lots of problems with development of cakephp authentication. for that purpose i'm trying to use table named reviewers, that contains fields username and password, of course.

i checked, and from login form proper data is sent (username and password).

file app_controller.php contains:

    class AppController extends Controller {
var $components = array('Auth', 'Session', 'Cookie', 'P28n');

    function beforeFilter() {

        $this->Auth->authenticate = ClassRegistry::init('Reviewer');

        Security::setHash('sha1'); // or sha1 or sha256
        $this->Auth->userModel = 'Reviewers';
    $this->Auth->fields = array('username' => 'username', 'password'=>'password');
    $this->Auth->loginRedirect = array('controller' => 'reviewers', 'action' => 'view');

    } 

how can i check and debug problem? error i get is that username and password combination is not correct.

what drives me mad is that i have alredy developed simular functionality before and it worked without problems........

pls help.

UPDATE: with cakephp debuggint tool, it looks like auth component is never called.

2
Are you overwriting your beforeFilter() function in a controller somewhere? Make sure to call parent::beforeFilter(); - user719367

2 Answers

0
votes

I've had similar problem with Cake 1.3, It appears that the Auth Component's auto hashing differs from hashing that is made when you save your users.

I ended up with this solution: I've added this in users controller before save.

$this->data['User']['password'] = Security::hash($this->data['User']['password']);

and now it works fine... maybe this will help.

0
votes

What if you try $this->Auth->authenticate =& ClassRegistry::init('Reviewer') to get a reference to the object.

AuthComponent - authenticate Property