Resetting to a default password

Dear all,

Please note I would like to change the password for all users. The reason is I am setting up a training server. I want to use a command something like:

UPDATE USERS SET password = ‘hashcode of pwd’ WHERE username <> ‘admin’

Please let me know how to generate the encrypted password to use in the above command.

Your help is much appreciated.

Regards

MSP

Hi @MSP,

the simplest way to do this is to use the UI/API to change the password of a user, and copy the hashed string from the database directly.
Alternatively, you could update your SQL query to set the password based on the record of the user you changed the password for.

1 Like

I think what @Stian is suggesting is the best approach.

So, I would:

  1. Go to DHIS2 and change the password of one user ‘traore’
  2. Execute the following code against the DB:

update users set password = ( select password from users where username = ‘traore’ ) where username <> ‘admin’;

Be aware: accessing directly the DB is a risky operation and in case of error can make your DHIS2 instance unsable!

Cheers.

1 Like

Out of curiosity, i just tested this for me & it works! Thanks @Stian and @jaime.bosque But for me it required a restart though

Also tried one code snippet to generate hash password which somebody had shared before on this forum. It works too but this is more complicated. Whatever Stian and Jaime suggested is so cool.

python -c 'import bcrypt; hash = bcrypt.hashpw("passwordGoesHere", bcrypt.gensalt(rounds=10, prefix=b"2a")); print(hash);'

1 Like

Thank you all for your prompt responses. Much appreciated.

In fact, I tried the same but it did not work. I guess the reason could be restarting the server.

Thank you once again to all. Have a wonderful day!

Regards

MSP

1 Like