devise icon indicating copy to clipboard operation
devise copied to clipboard

Reset password token is invalid

Open jimiguru opened this issue 12 years ago • 37 comments

I'm having a devil of a time with this one.

Rails 4 Devise 3.2.2 Postgres 9.3.2

Using @token, not @reset_password_token

Token is being set properly in the DB as is remember_password_sent_at timestamp.

I can query on the command line for users = @token and get the desired result.

No matter what, when attempting to reset the PW I get Reset password token invalid.

jimiguru avatar Feb 17 '14 15:02 jimiguru

Hrm, can you post the logs of the web request? Maybe the information is not being sent as expected?

josevalim avatar Feb 17 '14 15:02 josevalim

Sure:

Started PUT "/users/password" for x.x.x.x at 2014-02-17 09:47:49 -0500 Processing by Devise::PasswordsController#update as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"5jvqQjPZ6PDirMrQyL5Xl9k82SDf3ZVQxEnRqmfiO8o=", "user"=>{"reset_password_token"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Change my password"} User Load (6.6ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = '668f9f47b286a680a27ca836866f4dc95a780f846c860f752284ee0f670e916f' ORDER BY users.first ASC LIMIT 1 Rendered devise/shared/_links.erb (0.4ms) Rendered devise/passwords/edit.html.erb within layouts/sessions (8.5ms) Completed 200 OK in 150ms (Views: 61.2ms | ActiveRecord: 6.6ms)

jimiguru avatar Feb 17 '14 15:02 jimiguru

Yeah, with the tokens filtered, it doesn't really help. :P But you can see the token in the database query, is that the token you expected?

josevalim avatar Feb 17 '14 15:02 josevalim

Actually, the token being generated and stored in the DB differs than the token in the email.

For instance, I just attempted again and the token generated and stored by Devise is:

c79be8a0bf584bff6cade527f664e9ad1ade5808e9277520264d7bd2901f2718

The token in the email notification is:

/users/password/edit?reset_password_token=Fa_ByHWUk9r-ixHhxkfx"

jimiguru avatar Feb 17 '14 15:02 jimiguru

Relevant line from the mailer template:

<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %>

jimiguru avatar Feb 17 '14 15:02 jimiguru

Right. That's the idea. I am out of clues as what can be happening. Can you please provide an application that reproduces the error?

josevalim avatar Feb 17 '14 15:02 josevalim

So it may be that there is some hashing going on between the email process and Devise, sorry I'm not that familiar with the inner workings of Devise.

Anyway, the Token that is created and saved to the User model is the token that is being sought on the reset attempt.

It's a mystery to me why this doesn't work.

Token generated from log:

[["reset_password_token", "bfef35e411e3d3009ef7466dd85adf7bc03223d95c0dc5ead6f1cc8a61765aa4"]

Token in email: reset_password_token=_GEqBpbzGtuhR7jchNjC

Token in reset attempt: "reset_password_token" = 'bfef35e411e3d3009ef7466dd85adf7bc03223d95c0dc5ead6f1cc8a61765aa4'

jimiguru avatar Feb 17 '14 15:02 jimiguru

http://pm.paramzero.com:3001

There is no open enrollment, so I would need to create an account for you replicate the issue with.

jimiguru avatar Feb 17 '14 16:02 jimiguru

@jimiguru I mean an application we can see the source, there isn't much more we can do through external inspection.

josevalim avatar Feb 17 '14 16:02 josevalim

Oh sorry. It is a private repo, but I can add you as a contributor if you like.

jimiguru avatar Feb 17 '14 16:02 jimiguru

Sorry, it would be better if you provide a sample application that reproduces the error, as I can't take a better look right now.

josevalim avatar Feb 17 '14 16:02 josevalim

Closing as we need a way to reproduce the error to investigate this further. Thanks!

josevalim avatar Feb 22 '14 08:02 josevalim

I have the exact same problem. And I have an application to test it : https://github.com/infernalsirius/graep_active.git

I tested it locally in production and development environment and its working. Not on my vps.

infernalsirius avatar Sep 02 '14 03:09 infernalsirius

I also have the same problem. It doesn't happen all the time. But some time it happens for users that they cannot reset their password as it shows Reset password token is invalid error.

rqbukhari avatar Nov 12 '14 13:11 rqbukhari

I got the same issue with @jimiguru I'm not really sure why the token saved in the db didn't match the reset token being retrieved in the email. can anybody help us with this? thanks!

chocnut avatar Nov 24 '14 17:11 chocnut

I wanted to reproduce this. Let me check. I was yesterday looking into that portion of test code. Let me check also, though my current live apps are not having problem.

rubyrider avatar Nov 24 '14 17:11 rubyrider

@rubyrider I've created a rails 4 scaffold app with devise installed. can you please try it here if you can replicate it. http://3bd71a50.ngrok.com/ thanks!

chocnut avatar Nov 24 '14 18:11 chocnut

sure, I am doing it right now!

On Tue, Nov 25, 2014 at 12:39 AM, Peter Indiola [email protected] wrote:

@rubyrider https://github.com/rubyrider I've created a rails 4 scaffold app with devise installed. can you please try it here if you can replicate it. http://3bd71a50.ngrok.com/ thanks!

— Reply to this email directly or view it on GitHub https://github.com/plataformatec/devise/issues/2871#issuecomment-64241458 .

Regards, Irfan Ahmed Rizvi, Freelancer- Senior Ruby on Rails Developer https://www.odesk.com/users/~01c44db951895e4589 m: +880 1766 67 81 30 e: [email protected]

rubyrider avatar Nov 24 '14 18:11 rubyrider

Yah source code would be awesome! any pub repo available there? because I couldn't reproduce the problem also. I successfully changed my password. But I notice two following things:

  1. I tried first time to send password reset instruction, I got a 505 error
  2. I tried again. This time request made successfully. I got email.
  3. I tried to reset password from the link getting from email
  4. I failed to reset. invalid code.
  5. Suddenly I received email again. I click on reset link
  6. I successfully reset the password. @chocnut

rubyrider avatar Nov 24 '14 18:11 rubyrider

@rubyrider pushing it now to github.

chocnut avatar Nov 24 '14 18:11 chocnut