Cakephp 2.5.2 Auth始终返回false

用户名

Auth返回false。哈希密码与数据库中的哈希密码匹配,但仍返回false。

这是模型:

    App::uses('AppModel', 'Model');

    class User extends AppModel {

     public $validate = array(
    'username' => array(
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
         ),
         'password' => array(
          'notEmpty' => array(
            'rule' => array('notEmpty'),
            //'message' => 'Your custom message here',
            //'allowEmpty' => false,
            //'required' => false,
            //'last' => false, // Stop validation after this rule
            //'on' => 'create', // Limit validation to 'create' or 'update' operations
        ),
        ),
        );
       public function beforeSave($options = array()) {
    if (isset($this->data[$this->alias]['password'])) {

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

        ;
    }
    return true;



}
      }

这是AppController:

     class AppController extends Controller {


      public $components = array(
      'Session',
       'Auth' => array(
        'authenticate' => array(
            'Form' => array(

            )
        ),
        'loginAction'=>array(
            'controller'=>'users',
            'action'=>'login'
        ),
        'loginRedirect' => array(
            'controller' => 'references',
            'action' => 'admin_index'
        ),
        'logoutRedirect' => array(
            'controller' => 'home',
            'action' => 'index',
            'home'
        )

      )
     );
     public function beforeFilter() {
    $this->Auth->allow('index', 'view');
    }

     }

这是UsersController:

         public function login(){

        var_dump($this->Auth->login());die;
        if ($this->request->is('post')) {
        if ($this->Auth->login()) {

            return $this->redirect(array('controller'=>'references',   'action'=>'admin_index'));

        }

        $this->Session->setFlash(__('Invalid username or password, try again'));
         }
       }

和视图:

           <div class="users form">
         <?php echo $this->Session->flash('auth'); ?>
         <?php echo $this->Form->create('User',array('action'=>'login')); ?>
          <fieldset>
        <legend>
        <?php echo __('Please enter your username and password'); ?>
       </legend>
       <?php echo $this->Form->input('username');
       echo $this->Form->input('password');
      ?>
      </fieldset>
       <?php echo $this->Form->end(__('Login')); ?>
       </div>

我尝试使用BlowFish,但无法正常工作,因此在创建用户时登录了Auth默认哈希和哈希,然后登录match,因此哈希工作正常。我不明白问题是什么,所以请帮忙。

用户名

一个半小时后,我再次尝试,现在可以正常工作了。谁知道是什么问题。无论如何,如果您在上面的代码中发现任何问题,感谢您阅读并发布答案。谢谢!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章