2013-09-12 1 views
0

Я загрузил последнюю версию cakephp, которая представляет собой cakephp 2.4.Компонент Auth не проверяет пароль автоматически в cakephp 2.4

Когда я использую компонент Auth, он не проверяет пароль.

Когда я вижу SQL дамп показывает

SELECT User.id, User.role_id, User.username, User.password, 
User.email, User.first_name, User.last_name, User.activation_key, 
User.status, User.created, User.modified 
FROM cakephp.users AS User WHERE User.username = 'admin' 
AND User.status = 1 LIMIT 1 

Это должно быть

SELECT User.id, User.role_id, User.username, User.password, User.email, 
User.first_name, User.last_name, User.activation_key, User.status, 
User.created, User.modified FROM cakephp.users AS User 
WHERE User.username = 'admin' 
AND User.password = '32ddqdsd34sfgtbvge434' AND User.status = 1 LIMIT 1 

Мой код Auth компонент

$this->Auth->userModel = 'User'; 

$this->Auth->authenticate = array(
          'Form' => array(
          'scope' => array('User.status' => 1) 
          ) 
         ); 

$this->Auth->loginError  = __("login_failed_invalid_username_or_password"); 

$this->Auth->loginAction = array('admin' => true, 'controller' => 'admins', 'action' => 'login'); 

$this->Auth->loginRedirect = array('admin' => true, 'controller' => 'admins', 'action' => 'dashboard'); 

$this->Auth->authError  = __('you_must_login_to_view_this_information'); 

$this->Auth->autoRedirect = true; 
+0

CakePHP проверяет пароль после получения записи. Попробуйте ввести и ввести неверный пароль. Это работает? – Rob

ответ

1

Алгоритм хеширования изменился в версии 2.4. Теперь проверка пароля выполняется с помощью PHP и используется другой тип.

В модели

if (isset($this->data[$this->alias]['password'])) { 

    $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); 

} 

return true; 

} 

и контроллером

public $components = array(
    'Session', 
    /* add Auth component and set the urls that will be loaded after the login and logout actions is performed */ 
    'Auth' => array(
     'loginRedirect' => array('controller' => 'admins', 'action' => 'dashboard'), 
     'logoutRedirect' => array('controller' => 'admins', 'action' => 'home') 
    ) 
); 

время, чтобы прочитать это

http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html

0

Он не будет делать проверку пароля в одном SQL с выводом пользователь. Cake from 2.4 найдет пользователя (вы увидите этот вопрос), а затем проверьте пароль. Вы должны иметь правильную passwod в таблице, чтобы получить истинное от auth-> Войти

Решение: Login using AuthComponent in CakePHP 2.4