<?php
namespace App\Model\Entity;
use Cake\ORM\Entity;
/**
 * User Entity.
 */
class User extends Entity
{
    /**
     * Fields that can be mass assigned using newEntity() or patchEntity().
     * Note that '*' is set to true, which allows all unspecified fields to be
     * mass assigned. For security purposes, it is advised to set '*' to false
     * (or remove), and explicitly make individual fields accessible as needed.
     *
     * @var array
     */
    protected $_accessible = [
        '*' => true,
        'id' => false,
    ];
    protected function _setPassword($value)
    {
        $hasher = new DefaultPasswordHasher();
        return $hasher->hash($value);
    }
}
Here is my code in user.php. I am hashing the password and got this one error
Error: Class 'App\Model\Entity\DefaultPasswordHasher' not found File C:\xamp\htdocs\bookmarker\src\Model\Entity\User.php Line: 27
If you using cakephp version 4.0 and
already included these two for password hashing in your php file:
use Authentication\PasswordHasher\DefaultPasswordHasher;
{
    $hasher = new DefaultPasswordHasher();
    return $hasher->hash($password);
}
as mention in official cakephp 4.0 documentation
And still get an error like this:
Undefined type 'Authentication\PasswordHasher\DefaultPasswordHasher'. 
intelephense(1009) [50,23]
.
Then instead of using:
 use Authentication\PasswordHasher\DefaultPasswordHasher;
   
 $hasher = new DefaultPasswordHasher();
use this:
 use Cake\Auth\DefaultPasswordHasher as AuthDefaultPasswordHasher;
 $hasher = new AuthDefaultPasswordHasher();
I was missing the following line:
use Cake\Auth\DefaultPasswordHasher;
This was the reason why I got the error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With