0

I'm trying to understand how Cakephp works. I built a connection system with a simple form (username and password). When I click on the submit button (with the correct username and password), I always receive the same flash message, "Your username or password was incorrect". I tried many things, but I don't know how to fix it . If I'm logged, I want to be redirect on Google (it's the test i try) .

Look at my code :

login.ctp (View)

<?php
echo $this->Form->create('User',array('action'=>'login'));
echo $this->Form->inputs(array('legend'=>'Se connecter','username','password'));
echo $this->Form->end('Se connecter'); 
?>

UsersController

class UsersController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow();
    }
public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->User->id = $this->Auth->user("id");
                $this->redirect('http://www.google.fr');
            } else {
                $this->Session->setFlash('Your username or password was incorrect.');
            }
        }
    }
}

User (Model)

<?php
App::uses('AppModel', 'Model', 'AuthComponent', 'Controller/Component');

class User extends AppModel {

    public $actsAs = array('Acl' => array('type' => 'requester'));

    public function parentNode() {
        if (!$this->id && empty($this->data)) {
            return null;
        }
        if (isset($this->data['User']['group_id'])) {
            $groupId = $this->data['User']['group_id'];
        } else {
            $groupId = $this->field('group_id');
        }
        if (!$groupId) {
            return null;
        } else {
            return array('Group' => array('id' => $groupId));
        }
    }

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

    public $belongsTo = array(
        'Group' => array(
            'className' => 'Group',
            'foreignKey' => 'group_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
    );
}
?>

The password in my table user (sql) :

 password   char(40)    latin1_swedish_ci   
2
  • is your password hashed in the database? If yes, you should be careful with the (40).
    – Enjoyted
    Jun 30, 2014 at 15:57
  • yes it is . Thanks for the advice and what about my problem for the connexion ? Jun 30, 2014 at 19:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.