Skip to Content
Menu
This question has been flagged
4 Replies
2290 Views

I am using Odoo 13 and above.

For testing purpose, I want update passwords of all users ( excluding Admin ) in bulk because you know update one by one in backend is time consuming and error prone.

I think I can open psql and update res_user table directly, but the password there is encrypted, I should also update set password=encrypt('password').

However, I don't know how this encryption should be done.

Anyone knows the correct method to update password using SQL? Your help is appreciated.

Avatar
Discard
Best Answer

Hello, 

You can Use Below Module For Bulk Updating Password in Backend which is available in V14,15,16.

https://apps.odoo.com/apps/modules/14.0/bulk_update_user_password_sit

Avatar
Discard
Author Best Answer

Thanks for your swift suggestion.

Having a trial, it returns error.

UPDATE res_users SET password = crypt('password_for_test', gen_salt('sha1')) WHERE id in (6,10);

ERROR:  function gen_salt(unknown) does not exist

LINE 1: UPDATE res_users SET password = crypt('password_for_test', gen_salt('s...

                                                         ^

HINT:  No function matches the given name and argument types. You might need to add explicit type casts.

Is the gen_salt function version dependent?

I am using Odoo 13 CE. 


Avatar
Discard
Author

Pagico Flex's answer is inspiring though it's not completed and not working at least on my Odoo 13 CE.

But, upon further exploration to the issue, just learn more about the Odoo password.

First, the gen_salt function inside PostgreSQL is unknown but after CREATE EXTENSION crypt, then it becomes known.

Second, even gen_salt known but it doesn't support sha1 algorithm.

Third, whether odoo is uing sha1 unknown.

I have a select id, login, password from res_users; i found all password (encrypted) in db share a same format liked
$pbkdf2-sha512$25000$dC6ltJZSas2 .............

from start up to $25000$ are the same and in between a string sha512... does it mean it's using sha512?
sha512 also not supported by gen_salt

moreover, an identical string as prefix means concatenated encrypted password?

i am still looking for a solution for a SQL to change odoo user password altogether.

any idea is appreciated.

Author

I finally found the answer myself. It is very interesting and so simple that
update res_users set password = 'new_password' where id = xx;
that's it. simply give a password in plain text, no any complicated md5(), crypt() functions required.
then in psql,
select id, password you'll see the password in plain text, but....
you can login.
when u use backend to change password, the pw in db is encrypted.
very happy but do spend so much time on this, why didn't i just try the most simple way to update from the very beginning???

Best Answer

Hi,

You can utilize the following query to update the passwords for all users.


UPDATE res_users

SET password = md5('new_password')

WHERE id != (SELECT id FROM res_users WHERE login = 'admin');


Regards

Avatar
Discard
Author

md5 is not work.
upon issued the update password SQL using md5() the password stored in res_users not liked other passwords created from backend.
e.g. the length of encrypted password much shorter.

Best Answer

UPDATE res_users SET password = crypt('new_password', gen_salt('sha1')) WHERE login != 'admin'; 

Replace 'new_password' with the actual password you want to set, and 'admin' with the login of the user you want to exclude (e.g., the Administrator).

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 24
1458
1
Jun 23
1444
0
Aug 21
111
1
Mar 24
1015
1
May 23
2573