I want to migrate my cakephp2 project to cakephp3. I must retain the user's information. How to make them have the same way of generating a password? Here's how I generate passwords in cakephp2.
App::uses('AuthComponent', 'Controller/Component');
....
public function beforeSave($options = array()) {
$this->data['User']['password'] = AuthComponent::password(
$this->data['User']['password']
);
return true;
}
This is the way cakephp3 document generates passwords:
namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
/**
* User Entity.
*/
class User extends Entity
{
/**
* Fields that can be mass assigned using newEntity() or patchEntity().
*
* @var array
*/
protected $_accessible = [
'email' => true,
'password' => true,
'bookmarks' => true,
];
protected function _setPassword($value)
{
$hasher = new DefaultPasswordHasher();
return $hasher->hash($value);
}
}
They are not the same plaintext generate the same ciphertext. So, I can not retain cakephp2 user information. Could you tell me how to set up a successful migration project?