@@ -117,10 +117,22 @@ def sh256crypt(cls, password, salt, magic=magic_sha256):
117
117
class res_users (osv .osv ):
118
118
_inherit = "res.users"
119
119
120
+ def init (self , cr ):
121
+ """Encrypt all passwords at module installation"""
122
+ cr .execute ("SELECT id, password FROM res_users WHERE password IS NOT NULL and password != ''" )
123
+ for user in cr .fetchall ():
124
+ self ._set_encrypted_password (cr , user [0 ], user [1 ])
125
+
126
+ def _set_encrypted_password (self , cr , uid , plain_password ):
127
+ """Set an encrypted password for a given user"""
128
+ salt = gen_salt ()
129
+ stored_password_crypt = md5crypt (plain_password , salt )
130
+ cr .execute ("UPDATE res_users SET password = '', password_crypt = %s WHERE id = %s" ,
131
+ (stored_password_crypt , uid ))
132
+
120
133
def set_pw (self , cr , uid , id , name , value , args , context ):
121
134
if value :
122
- encrypted = md5crypt (value , gen_salt ())
123
- cr .execute ("update res_users set password='', password_crypt=%s where id=%s" , (encrypted , id ))
135
+ self ._set_encrypted_password (cr , id , value )
124
136
del value
125
137
126
138
def get_pw ( self , cr , uid , ids , name , args , context ):
@@ -144,9 +156,7 @@ def check_credentials(self, cr, uid, password):
144
156
if cr .rowcount :
145
157
stored_password , stored_password_crypt = cr .fetchone ()
146
158
if stored_password and not stored_password_crypt :
147
- salt = gen_salt ()
148
- stored_password_crypt = md5crypt (stored_password , salt )
149
- cr .execute ("UPDATE res_users SET password='', password_crypt=%s WHERE id=%s" , (stored_password_crypt , uid ))
159
+ self ._set_encrypted_password (cr , uid , stored_password )
150
160
try :
151
161
return super (res_users , self ).check_credentials (cr , uid , password )
152
162
except openerp .exceptions .AccessDenied :
0 commit comments