How to manually change the password using Devise

twitter logo github logo Updated on ・1 min read

When you create a web application with Rails, using devise makes it easy to create a login authentication part.

By using devise, the user's password is encrypted and stored.

There are times when you want to change your password by directly modifying data as you are developing.
In that case, do as follows.

user = User.find(ID of the user whose password you want to change)
user.password = 'new password'
user.password_confirmation = 'new password'
user.save

by @nishina555

twitter logo DISCUSS (4)
markdown guide
 

Or you can use Devise::Recoverable#reset_password:

 User.find(id).reset_password(password, password)

If you're not using Devise::Recoverable, you can at least assign both passwords in one go:

user.password = user.password_confirmation = 'new password'
 
 

You are right!
We may not need to create the filed of confirming a password to forms.
Even if there is the field, it may be useless because many users put it just by copying and pasting the password.

I wrote the post because there was the field of confirming the password in the web service which I develop.

I saw Airbnb's website, and I wasn't asked to confirm the password.

In Japan, confirming the password is standard for web service, but it may be getting rid of in near future.

Classic DEV Post from Nov 1 '18

Is Today the Best Time to be a Developer? No...but We're Getting Better.

While working as a developer certainly has its rewards, there are some major issues we need to address.

Toshiharu Nishina profile image
A web developer for the fifth year.Rails/React/GraphQL.
Sign up (for free)

dev.to is where software developers stay in the loop and avoid career stagnation.