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'

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 16 '18

What dev topic do you think you should understand, but don't?

An all-too-common experience

Toshiharu Nishina profile image
A web developer for the fifth year.Rails/React/GraphQL.