How to reset password for users in PostgreSQL database

Hello everybody,

We have some questions about how to reset password for users in discourse.
We know that the command “RAILS_ENV=production /usr/local/bin/bundle exec rake admin:create” can reset the password for existing users or create a new admin user. But we do not want to reset password for admin user using this method. We want to reset password for users in PostgreSQL database.
The user information is stored in users table in postgresql database. And we can check the users and password using “select id, username, name, password_hash from users;”. So we have two questions.

  1. How does the password encrypt? MD5 ? Sha256?
  2. Can we reset password using " UPDATE users SET password_hash = ‘there is a hash password’ WHERE id=1; " ?

If someone has an idea it would be really helpful, thank you!

What problem are you solving? Why not have them use the reset password link and set it themselves?

I would do it from the rails console rather than sql. I would have to look at the source to get the code.

1 Like

From the rails console:

User.find_by(username: 'gollum').update!(password: 'shiiiire!-BAGGINS!')
3 Likes

@supermathie , thank you very much!
We can reset password by

RAILS_ENV=production rails runner 'User.find_by_email("admin@example.com").update!(password:"AdminAdmin1234566xxxxxx")'
2 Likes