From d8ba91b2f1b551701079e83b27ea1b0e28caac00 Mon Sep 17 00:00:00 2001 From: Carlos Oliveira Date: Thu, 12 Mar 2015 12:19:30 -0300 Subject: [PATCH] Normalized empty passwords for resetting --- colab/accounts/migrations/0005_auto_20150312_1454.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+), 0 deletions(-) create mode 100644 colab/accounts/migrations/0005_auto_20150312_1454.py diff --git a/colab/accounts/migrations/0005_auto_20150312_1454.py b/colab/accounts/migrations/0005_auto_20150312_1454.py new file mode 100644 index 0000000..4c064f1 --- /dev/null +++ b/colab/accounts/migrations/0005_auto_20150312_1454.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.contrib.auth.hashers import make_password +from django.db import models, migrations +from django.utils.crypto import get_random_string + + +def normalize_password(apps, schema_editor): + User = apps.get_model("accounts", "User") + for user in User.objects.all(): + if len(user.password) is not 0: + continue + + rand_pwd = get_random_string() + + user.password = make_password(rand_pwd) + user.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0004_auto_20150311_1818'), + ] + + operations = [ + migrations.RunPython(normalize_password) + ] -- libgit2 0.21.2