Closed TiagoSilvaPereira closed 5 years ago
Hi there,
Thanks for reporting but it looks like this is a question which can be asked on a support channel. Please only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repo you can try one of the following channels:
However, this issue will not be locked and everyone is still free to discuss solutions to your problem!
Thanks.
Hi, @driesvints thanks for responding :smile: ... I think the problem is occurring inside the library because I noticed that what is failing is the exits() method inside DatabaseTokenRepository. It fails only on Test Env.
Can you reconsider opening this issue?
Thanks
Hi @driesvints can you reconsider opening the issue? It seems like the problem occurs inside the library (I debugged the code and the problem seems to happen on DatabaseTokenRepository).
thanks
@TiagoSilvaPereira you're using the check
method wrong. The first argument should be your unhashed password. Please try a support channel first next time. Thanks!
Hi @driesvints thanks for responding. I'm not using the check() method, I'm using the native ResetsPasswords and SendsPasswordResetEmails traits only. I think the issue is inside DatabaseTokenRepository that is internal Laravel code. I debugged and noticed that it is happening inside this code.
Please note that this code is inside Illuminate\Auth\Passwords\DatabaseTokenRepository and the issue happens only on Test Environment:
public function exists(CanResetPasswordContract $user, $token)
{
$record = (array) $this->getTable()->where(
'email', $user->getEmailForPasswordReset()
)->first();
return $record &&
! $this->tokenExpired($record['created_at']) &&
$this->hasher->check($token, $record['token']);
}
Thanks
There is no way the Laravel code is incorrect here. Otherwise, Forge, Envoyer, Vapor, etc. would all have a broken password reset?
Hey @TiagoSilvaPereira. I was wrong myself at first. The first argument is your random generated token for your reset password record. The same token is hashed first before it's stored in the database record.
@taylorotwell, @driesvints thanks for responding... It is happening only on Test Environment, as explained above (Works well on production). May be an issue with my test env?
Thanks
@TiagoSilvaPereira
// Here we have the token
$token = DB::table('password_resets')
->whereEmail($user->email)
->first()
->token;
You're just retrieving the hashed token from the DB here which won't work. You need the token before it was hashed.
@driesvints Thank you very much, I'll take a look at it. Sorry for bothering you. Best Regards
Hi,
Recently, I created a reset password feature for an API using the Laravel ResetsPasswords and SendsPasswordResetEmails traits. It worked very well on the Development Environment, but the tests to reset the password are failing. Investigating, I noticed that what is failing is this method inside DatabaseTokenRepository:
Most specifically, this line is returning false on Test enviroment:
I printed both $token and $record['token'] before the return method and it shows:
So both tokens are identical. Is this the correct behavior? Am I doing something wrong?
Thanks :smile: !
This is the test I'm doing:
And this is the Trait I created to reset the password (I'm using on my AccountController):
And the routes: