1

I want to make a change password in rails i want to enter the old password as a string and check it with the encrypted one in the database i am using Devise gem how can i do this

mohamed
  • 135
  • 1
  • 14
  • Devise provides you with this functionality already. Have a look at https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-password – IngoAlbers Oct 08 '15 at 20:28
  • your link was very useful thanks it helped a lot could you please make it as an answer so i could accept it – mohamed Oct 09 '15 at 13:40
  • Possible duplicate of [how verify user password in devise](http://stackoverflow.com/questions/4320921/how-verify-user-password-in-devise) – Shiva Oct 09 '15 at 14:30
  • @mohamed ok. glad it worked out – IngoAlbers Oct 09 '15 at 19:56

2 Answers2

5

You want Devise's valid_password? method.

> user = User.find(1)
> user.valid_password?('invalidpassword')
=> false
> user.valid_password?('therealpassword')
=> true
Philip Hallstrom
  • 19,673
  • 2
  • 42
  • 46
1

Devise already provides you with this functionality. It should probably work out of the box using the edit_user_registration_path.

Have a look at https://github.com/plataformatec/devise/wiki/How-To%3a-Allow-users-to-edit-their-password to find some more information.

IngoAlbers
  • 5,722
  • 6
  • 31
  • 45