Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16.0 - [IMP] base: Speed-up password encrypt for staging instances sharing the same password #598

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions odoo/addons/base/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,24 @@ def init(self):
# match the "extended" MCF and pass those through passlib.
# Alternative: iterate on *all* passwords and use CryptContext.identify
cr.execute(r"""
SELECT id, password FROM res_users
SELECT array_agg(id), password FROM res_users
WHERE password IS NOT NULL
AND password !~ '^\$[^$]+\$[^$]+\$.'
GROUP BY password
""")
if self.env.cr.rowcount:
Users = self.sudo()
for uid, pw in cr.fetchall():
Users.browse(uid).password = pw
for uids, pw in cr.fetchall():
Users.browse(uids).password = pw

def _set_password(self):
ctx = self._crypt_context()
plain_encrypt = {}
for user in self:
self._set_encrypted_password(user.id, ctx.hash(user.password))
if user.password not in plain_encrypt:
plain_encrypt[user.password] = ctx.hash(user.password)
pwd_encrypt = plain_encrypt[user.password]
self._set_encrypted_password(user.id, pwd_encrypt)

def _set_encrypted_password(self, uid, pw):
assert self._crypt_context().identify(pw) != 'plaintext'
Expand Down