0
votes

I have tried most if not all tutorials for CakePHP 1.3 on their Auth method and non seem to work on CakePHP 2.0.

I can add users, hash the passwords, but the login feature does not work. It just refreshes the page when I click on login. No errors, no nothing.

I would appreciate some tips please and thank you for reading my question.

This my code public function login() {

    if ($this->request->is('post') )
    {

        if( $this->Auth->login() )
        {

            // the redirect() function in the Auth class redirects us
            // to the url we set up in the AppController.
            return $this->redirect( $this->Auth->redirect());
        }
        else
        {

            $this->Session->setFlash(__('Email or password is incorrect',true));
        }
    }
}

Thanks, Mahadeva Prasad

1
is it possible that it is put? is('put') in this case? - mark

1 Answers

0
votes

First of all check how you have hash the password.Also check the field length in database. Preferred - varchar(255) The password will be hash as follows.

class User extends AppModel {
   public function beforeSave($options = array()) {
        $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        return true;
   }
} 

Also as you are using FormAuthenticate try using this when declaring component.

public $components = array(
'Auth' => array(
    'loginAction' => array(
        'controller' => 'users',
        'action' => 'login',            
    ),       
    'authenticate' => array(
        'Form' => array(
            'fields' => array('username' => 'username')
        )
    )
)
);

For more information refer http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html