Devise password reset from Rails console

Ruby on-RailsRubyRuby on-Rails-3DeviseRails Console

Ruby on-Rails Problem Overview


While running an app how do you select a user by email address and then set the password manually within rails console for Devise?

Also, where would I go to review documentation to cover more details in this regard to manipulation of accounts while using Devise?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

Modern devise allows simpler syntax, no need to set the confirmation field

user.password = new_password; user.save
# or
user.update(password: new_password)

Solution 2 - Ruby on-Rails

# $ rails console production
u=User.where(:email => '[email protected]').first
u.password='userpassword'
u.password_confirmation='userpassword'
u.save!

Solution 3 - Ruby on-Rails

If you run the following in the rails console it should do the trick:

User.find_by(email: 'user_email_address').reset_password!('new_password','new_password')

http://www.rubydoc.info/github/plataformatec/devise/Devise/Models/Recoverable

Solution 4 - Ruby on-Rails

You can simply update password field, no need for confirmation password, devise will save it in encrypted form

u = User.find_by_email('user@example.com')
u.update_attribute(:password, '123123')

Solution 5 - Ruby on-Rails

For some reason, (Rails 2.3??)

user = User.where(:email => email).first

didn't work for me, but

user = User.find_by_email('[email protected]')

did it.

Solution 6 - Ruby on-Rails

1.Login in to ralis console

$ sudo bundle exec rails console production

2.Then update the administrator's password

irb(main):001:0> user = User.where("username = 'root'")
irb(main):002:0> u = user.first
irb(main):003:0> u.password="root2014@Robin"
=> "root2014@Robin"
irb(main):004:0> u.password_confirmation="root2014@Robin"
=> "root2014@Robin"
irb(main):005:0> u.save
=> true
irb(main):006:0> exit

3.Refresh the login page, use the new password to login, enjoy!

Good Luck!

Solution 7 - Ruby on-Rails

User.find_by_email('[email protected]').update_attributes(:password => 'password')

Solution 8 - Ruby on-Rails

If your account is locked from too many login attempts, you may also need to do:

user.locked_at = ''
user.failed_attempts = '0'
user.save!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionylluminateView Question on Stackoverflow
Solution 1 - Ruby on-RailsSergio TulentsevView Answer on Stackoverflow
Solution 2 - Ruby on-RailsEric GuoView Answer on Stackoverflow
Solution 3 - Ruby on-RailsgstraehleView Answer on Stackoverflow
Solution 4 - Ruby on-RailsKshitijView Answer on Stackoverflow
Solution 5 - Ruby on-RailsvalkView Answer on Stackoverflow
Solution 6 - Ruby on-RailsrobinwenView Answer on Stackoverflow
Solution 7 - Ruby on-RailscopremesisView Answer on Stackoverflow
Solution 8 - Ruby on-RailsEnzioView Answer on Stackoverflow