Login [ Auth->identify() ] always false on CakePHP 3

前端 未结 5 2393
孤街浪徒
孤街浪徒 2020-12-10 05:18

I started using CakePHP 3 after a time using CakePHP 2 and I am having troubles to create the authentication login.

The new auth function $this->Auth->id

相关标签:
5条回答
  • 2020-12-10 05:28

    Solved: The type on database was less than required. Changed to varchar(255) and now works fine :)

    0 讨论(0)
  • 2020-12-10 05:29

    I came out with a solution just by adding use Cake\Auth\DefaultPasswordHasher; and its following override method _setPassword.

    Here is the change:

    Model/table.php

    <?php
    
    use Cake\Auth\DefaultPasswordHasher;
    
    // Somewhere in the class
    protected function _setPassword($password) {
        return (new DefaultPasswordHasher)->hash($password);
    }
    
    0 讨论(0)
  • 2020-12-10 05:40

    CakePHP3 uses a different hashing algorithm by default than 2 (bcrypt vs. SHA1), so you need to make your password length longer. Change your password field to VARCHAR(255) to be safe.

    When CakePHP 3 tries to identify your in-memory hashed password from this->Auth->identify() vs. the hashed password in the database, it will never match because some characters are missing. Changing to 255 is more than needed, but can help future proof if an even more secure hash is used in the future. 255 is recommended because the the character count can be stored in one byte.

    0 讨论(0)
  • 2020-12-10 05:40

    I had the same issue. The Login [ Auth->identify() ] was not working for me. Changing password length in db will resolve the issue.

    0 讨论(0)
  • 2020-12-10 05:41

    Hi share my snippets to Login Auth, all Testing is OK, in CakePHP 3.1, customs (Table + view login BootStrap 3 + SQL base + custom bootstrap.php for Spanish in Inflector::rules(*******))

    All code in

    https://bitbucket.org/snippets/eom/rLo49

    0 讨论(0)
提交回复
热议问题