summaryrefslogtreecommitdiff
path: root/addons/base_crypt/crypt.py
diff options
context:
space:
mode:
authorVo Minh Thu <vmt@openerp.com>2010-12-23 17:31:00 +0100
committerVo Minh Thu <vmt@openerp.com>2010-12-23 17:31:00 +0100
commite9c8d9ce770db7920fbf3393deeb01553ceb91ac (patch)
tree48be2add4b60722b37b7aa172283973b89ce133f /addons/base_crypt/crypt.py
parenta0640060f525e4fdc1873d8d3ec9f434256ff3bc (diff)
[IMP] base_crypt: encrypting all passwords at the first check.
bzr revid: vmt@openerp.com-20101223163100-ib3qf9i4kiqkpn77
Diffstat (limited to 'addons/base_crypt/crypt.py')
-rwxr-xr-xaddons/base_crypt/crypt.py29
1 files changed, 18 insertions, 11 deletions
diff --git a/addons/base_crypt/crypt.py b/addons/base_crypt/crypt.py
index 4c03442b9d0..3320cdf6ee0 100755
--- a/addons/base_crypt/crypt.py
+++ b/addons/base_crypt/crypt.py
@@ -160,7 +160,7 @@ class users(osv.osv):
# Return early if no such id.
return False
- stored_pw = self.maybe_encrypt_and_store(cr, stored_pw, id)
+ stored_pw = self.maybe_encrypt(cr, stored_pw, id)
res = {}
res[id] = stored_pw
@@ -202,7 +202,7 @@ class users(osv.osv):
# Return early if there is no such login.
return False
- stored_pw = self.maybe_encrypt_and_store(cr, stored_pw, id)
+ stored_pw = self.maybe_encrypt(cr, stored_pw, id)
# Calculate an encrypted password from the user-provided
# password.
@@ -222,7 +222,7 @@ class users(osv.osv):
def check(self, db, uid, passwd):
print ">>>>>> check"
# TODO cannot use the cache as it would prevent the update by
- # maybe_encrypt_and_store.
+ # maybe_encrypt.
#cached_pass = self._uid_cache.get(db, {}).get(uid)
#if (cached_pass is not None) and cached_pass == passwd:
# return True
@@ -254,17 +254,24 @@ class users(osv.osv):
# self._uid_cache[db] = {uid: passwd}
return bool(res)
- def maybe_encrypt_and_store(self, cr, pw, id):
- # Calculate a new password 'encrypted' from 'pw' if the
- # latter isn't encrypted yet. Use it to update the database entry
- # and return it, or simply return 'pw'.
+ def maybe_encrypt(self, cr, pw, id):
+ # If the password 'pw' is not encrypted, then encrypt all passwords
+ # in the db. Returns the (possibly newly) encrypted password for 'id'.
if pw[0:len(magic_md5)] != magic_md5:
- encrypted = encrypt_md5(pw, gen_salt())
- cr.execute('update res_users set password=%s where id=%s',
- (encrypted.encode('utf-8'), id))
+ cr.execute('select id, password from res_users')
+ res = cr.fetchall()
+ for i, p in res:
+ encrypted = p
+ if p[0:len(magic_md5)] != magic_md5:
+ encrypted = encrypt_md5(p, gen_salt())
+ print ">>>>>> changing %s to %s" % (p, encrypted)
+ cr.execute('update res_users set password=%s where id=%s',
+ (encrypted.encode('utf-8'), i))
+ if i == id:
+ encrypted_res = encrypted
cr.commit()
- return encrypted
+ return encrypted_res
return pw
users()