Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CakePHP 3.0 Authentication #66

Closed
archanavhire opened this issue Jun 9, 2014 · 18 comments
Closed

CakePHP 3.0 Authentication #66

archanavhire opened this issue Jun 9, 2014 · 18 comments
Milestone

Comments

@archanavhire
Copy link

I am able to add user but still Auth login is not working.
link of gist is following
https://gist.github.com/archanavhire/1460ebc16a7510d8d589

@lorenzo lorenzo added this to the 3.0.0 milestone Jun 9, 2014
@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

what is not working exactly? Password hasher were recently changed in 3.0, you may want to take a look at the auth tutorial again and perhaps manually reset passwords for your current database if it is an option for you. In the future, please open tickets in cakephp/cakephp

@archanavhire
Copy link
Author

I am not able to login after submit on login button, always going in else part.
I am giving right username and password.please look in to my auth login code.
I followed all steps for authentication.
https://gist.github.com/archanavhire/1460ebc16a7510d8d589

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

Can you debug if the hashed password match? Go into the BaseAuthenticate class and debug the hashed password value and compared to the one in the database

@archanavhire
Copy link
Author

I found the bug, which is in FormAuthenticate class. _checkFields of FormAuthenticate class return false because of username field(In my form it is email). but I already mention in app controller for email field instead of username.
Still not able to fix this bug.

@ADmad
Copy link
Member

ADmad commented Jun 9, 2014

The problem was in your config

$this->Auth->config('authenticate', ['Form'=>['username'=>'email','password'=>'password']]);

you are missing the fields key. It should be

$this->Auth->config('authenticate', ['Form'=>['fields' =>['username'=>'email','password'=>'password']]]);

@ADmad ADmad closed this as completed Jun 9, 2014
@archanavhire
Copy link
Author

problem is in $this->passwordHasher()->check($password, $result[$fields['password']]) function which is in BaseAuthenticate class.
function is returning false even if I got result array.

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

Can you go into the hasher code and compare what it produces versus what you have stored in the database?

@archanavhire
Copy link
Author

Yes I did it and I found record in database. It is also returning result in $result variable.
But after that its again checking passwordHasher which is returning false.

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

you're still not answering my question, how does the password stored in your database compare to what the password hasher is producing?

@archanavhire
Copy link
Author

I stored password in blowfish hash code which is 50 char.
App\Model\Entity\User.php

hash($password); } } ?>

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

can you paste here the password stored in your database and the one that is checked in the password hasher class?

@archanavhire
Copy link
Author

In database :
$2y$10$6dab8w1rJ0RP411hkl.B8OBwzwaK0ZgnZoR7/XjmBPo
in result variable:
[password] => $2y$10$6dab8w1rJ0RP411hkl.B8OBwzwaK0ZgnZoR7/XjmBPo

@archanavhire
Copy link
Author

ok, I got it.
In $this->passwordHasher()->check($password, $result[$fields['password']]) function
$password is in simple text and $result[$fields['password']] is hashed so that its returning false.

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

Both passwords are the same, how come the password checker returns false then? Can you help us debug that?

@lorenzo
Copy link
Member

lorenzo commented Jun 9, 2014

If you are using the laters CakePHP 3.0, please use SimplePasswordHasher instead of Blowfish

@archanavhire
Copy link
Author

As you suggested me, I switched from Blowfish to SimplePasswordHasher. But still authentication is not working because password is not matching.following code returning false.
password_verify($password, $hashedPassword);

password return by hasher :
'$2y$10$dDcxwWtDJVYnRfNX.wIBJuQdokyX65ZpaQCcqvQSQOiGH7yf7HMAG'
password in my db:
'$2y$10$HJ9urHeVBzXezb0Hh13AJeU3PquK2f4yLIrl9bHNVWl'

My updated gist link is:
https://gist.github.com/archanavhire/842266d5953c0df413f2

@markstory
Copy link
Member

You DB column is probably too short, bcrypt hashes are much longer than sha1's. If you are using a fixed length column they will be truncated.

@archanavhire
Copy link
Author

Thank you very much. Now its working.
:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants