Hello,
I have to upgrade app from cakephp 2 to 4 and I follow cake documentation, but get error messages:
Argument 2 passed to Authentication\PasswordHasher\FallbackPasswordHasher::check() must be of the type string, resource given, called in /vagrant/vendor/cakephp/authentication/src/Identifier/PasswordIdentifier.php on line 131
CakePHP 2.5.1 password hasher
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
@CakePHP 4.2 Applications
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
{
$authenticationService = new AuthenticationService([
'unauthenticatedRedirect' => '/users/login',
'queryParam' => 'redirect',
]);
// Load identifiers, ensure we check email and password fields
$authenticationService->loadIdentifier('Authentication.Password', [
'fields' => [
'username' => 'username',
'password' => 'password',
],
'resolver' => [
'className' => 'Authentication.Orm',
],
'passwordHasher' => [
'className' => 'Authentication.Fallback',
'hashers' => [
'Authentication.Default',
[
'className' => 'Authentication.Legacy',
'hashType' => 'md5',
//'salt' => false, // turn off default usage of salt
],
],
],
]);
// Load the authenticators, you want session first
$authenticationService->loadAuthenticator('Authentication.Session');
// Configure form data check to pick email and password
$authenticationService->loadAuthenticator('Authentication.Form', [
'fields' => [
'username' => 'username',
'password' => 'password',
],
'loginUrl' => '/users/login',
]);
return $authenticationService;
}
How to fix?