简体   繁体   中英

Change password of other user in using devise gem

I have used devise gem for authentication. There are multiple users and i am admin. I want to change the password of other users. Is it possible to do so?

I can't think of a better way but you can implement an action which passes the new password typed in a form field and do the following. The code below will work in the rails console as well.(tested on Device 4.2.0)

u = User.find(user_id)
u.password = "changed_password"
u.save

EDIT: I would strongly suggest to rethink doing this . How would the existing user know what his password is. Alternative - you may also build a mechanism so that users can use the forgot password method and set their password themselves. To do so you can make the encrypted_password null and send them a forgot password email(with appropriate message in the mail that their current password has expired and they need to set a new one) so that they can use it to set their password themselves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM