migration: replace empty passwords with random ones on upgrade stable
authorJulien Cristau <julien.cristau@logilab.fr>
Fri, 31 Aug 2012 13:55:59 +0200
branchstable
changeset 8522 85b1c4b36d1d
parent 8521 dfdffebce8a4
child 8523 410cbb14f0f5
migration: replace empty passwords with random ones on upgrade
misc/migration/3.15.4_Any.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/misc/migration/3.15.4_Any.py	Fri Aug 31 13:55:59 2012 +0200
@@ -0,0 +1,11 @@
+from logilab.common.shellutils import generate_password
+from cubicweb.server.utils import crypt_password
+
+for user in rql('CWUser U WHERE U cw_source S, S name "system", U upassword P, U login L').entities():
+    salt = user.upassword.getvalue()
+    if crypt_password('', salt) == salt:
+        passwd = generate_password()
+        print 'setting random password for user %s' % user.login
+        user.set_attributes(upassword=passwd)
+
+commit()