“Invalid username or password” when logging in

There are other threads with this issue, but none of the solutions there have fixed it for me. I am trying to get a user system setup with CakePHP.

When I go to /users/add and create an account, the password is hashed, but when I login, I get the error Invalid username or password regardless of if I enter the email and password, or even the email and hashed password. I can’t seem to find the issue, any help would be appreciated.

Here are the relevant files, let me know if you need anything else:

login.php - https://pastebin.com/awUzAs52

UserController.php - https://pastebin.com/vJMs7JgT

Application.php - https://pastebin.com/Pg7UNQBd

AppController.php - https://pastebin.com/gen2yraP

UsersTable.php - https://pastebin.com/dduCAfAj

User.php - https://pastebin.com/Wd3XJPU9

Thanks in advance for any help you can provide.

Isn’t the Authentication config method in Application.php supposed to be:

public function getAuthenticationService(ServerRequestInterface $request)

since the Middleware calls that hook?

I see your Application.php opts for

‘protected function configAuth(): \Authentication\AuthenticationService’.

You are calling the config method as an argument when you load the middleware on the queue but I don’t think that will work. The middleware needs to get an instance of the the application so recursive calling of the middleware queue can proceed.

There is a second constructor argument for the middleware but I don’t think this a place to put your config method either. Naming the method properly and letting the middleware call it will be the way to go.

1 Like

I tried that and it threw an error, I followed the CMS tutorial for setting up users, and I have since copied as many of the files as I can from there, and I still can’t get it working. Do you have any other ideas on what it could be (or what files I should look into)?

what was the error and what did your modifications look like?

I modified it the way you initially said to, and it did a whitescreen, I modified the AppController.php and Application.php files to be the same as the finished tutorial (https://github.com/cakephp/cms-tutorial/), but that doesn’t seem to be helping anything.

Is this the current application.php you’re using? If so, I do miss some of these?

use Authentication\AuthenticationService;
use Authentication\AuthenticationServiceInterface;
use Authentication\AuthenticationServiceProviderInterface;
use Authentication\Middleware\AuthenticationMiddleware;

Added those in, it is still not working.

use Cake\Auth\DefaultPasswordHasher;


use Authentication\PasswordHasher\DefaultPasswordHasher;

in User.php?

Tried that, it still isn’t working, even when I create a new user and try to login with that.

Thanks to everyone’s help, I fixed it by re-baking the user controller and following the instructions on the CMS tutorial again. It is working now, thanks again for the help!