Skip to content

Commit 9f2c9bd

Browse files
committed
Migrate old passwords to be unusable
1 parent 8db6096 commit 9f2c9bd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.16 on 2018-10-11 17:28
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
7+
8+
def forwards_func(apps, schema_editor):
9+
User = apps.get_model('auth', 'User')
10+
11+
old_password_patterns = (
12+
'sha1$',
13+
# RTD's production database doesn't have any of these
14+
# but they are included for completeness
15+
'md5$',
16+
'crypt$',
17+
)
18+
for pattern in old_password_patterns:
19+
users = User.objects.filter(password__startswith=pattern)
20+
for user in users:
21+
user.set_unusable_password()
22+
user.save()
23+
24+
25+
class Migration(migrations.Migration):
26+
27+
dependencies = [
28+
('core', '0004_ad-opt-out'),
29+
('auth', '0008_alter_user_username_max_length'),
30+
]
31+
32+
operations = [
33+
migrations.RunPython(forwards_func),
34+
]

0 commit comments

Comments
 (0)