Quentin
Quentin

Reputation: 1135

Rails Devise user password is always invalid (tested in rails console)

I have one particular user in my rails app for which I can't log in anymore, the password is always invalid, even though I changed it manually. Here's what I do in rails console :

> me = User.find(10)
> me.password = '123456789'
> me.save
  (0.3ms)  BEGIN
 User Exists (0.6ms)  SELECT  1 AS one FROM "users" WHERE ("users"."email" = '[email protected]' AND "users"."id" != 10) LIMIT 1
 SQL (0.7ms)  UPDATE "users" SET "encrypted_password" = $1, "updated_at" = $2 WHERE "users"."id" = $3  [["encrypted_password", "$2a$10$mrhWiOT3pu6YldtYRD/bC.wuqPthyfJhiqdGkYv14xCafVQNTodWG"], ["updated_at", "2016-08-08 10:43:34.715229"], ["id", 10]]
  (31.3ms)  COMMIT
=> true
> me.valid_password?('123456789')
=> nil

This is only with this particular user id 10. I do the exact same thing with any other user it works. What could be wrong ?

EDIT : I tried also with password confirmation but that's not the issue. As I said, the exact manipulation works fine with any user except this one of ID 10

EDIT 2 : I found the solution in this thread : Rails/Devise: valid_password? method returns nil

Upvotes: 0

Views: 627

Answers (1)

power
power

Reputation: 1265

I think probably you need to set password_confirmation as well, Try below code.

> me = User.find(10)
> me.password = '123456789'
> me.password_confirmation = '123456789'
> me.save

Upvotes: 2

Related Questions