misc/migration/3.15.4_Any.py
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 24 Nov 2014 11:49:28 +0100
changeset 10058 d47c318f95b2
parent 8522 85b1c4b36d1d
child 10589 7c23b7de2b8d
permissions -rw-r--r--
[migration/bootstrap] add explicit index removal for sqlserver, be tolerant to migration replay Closes #4618944.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8522
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     1
from logilab.common.shellutils import generate_password
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     2
from cubicweb.server.utils import crypt_password
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     3
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     4
for user in rql('CWUser U WHERE U cw_source S, S name "system", U upassword P, U login L').entities():
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     5
    salt = user.upassword.getvalue()
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     6
    if crypt_password('', salt) == salt:
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     7
        passwd = generate_password()
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     8
        print 'setting random password for user %s' % user.login
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     9
        user.set_attributes(upassword=passwd)
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    10
85b1c4b36d1d migration: replace empty passwords with random ones on upgrade
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    11
commit()