Skip to content
Snippets Groups Projects
Commit 4bc4e677 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Revised setstudentpassword management command

parent a5db40f0
No related branches found
No related tags found
1 merge request!109Revised setstudentpassword management command
Pipeline #
import csv
import re
import secrets
import sys
......@@ -17,7 +18,9 @@ class Command(BaseCommand):
)
def _handle(self, *args, output=sys.stdout, instance="", **kwargs):
with open('/usr/share/dict/words') as words:
with open('/usr/share/dict/words') as f:
# strip punctuation
words = set(re.sub(r"[^a-z]", "\n", f.read().lower()).split('\n'))
choose_from = list({word.strip().lower()
for word in words if 5 < len(word) < 8})
......@@ -26,7 +29,7 @@ class Command(BaseCommand):
['Name', 'Matrikel', 'Username', 'password', 'instance'])
for student in get_user_model().get_students():
password = ''.join(secrets.choice(choose_from) for _ in range(3))
password = '-'.join(secrets.choice(choose_from) for _ in range(3))
student.set_password(password)
student.save()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment