| 1 |
""" |
|---|
| 2 |
Management utility to create anonuser. |
|---|
| 3 |
""" |
|---|
| 4 |
import random |
|---|
| 5 |
import string |
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
from django.contrib.auth.models import User, get_hexdigest |
|---|
| 9 |
|
|---|
| 10 |
class Command(BaseCommand): |
|---|
| 11 |
option_list = BaseCommand.option_list |
|---|
| 12 |
help = 'Used to create an anonuser.' |
|---|
| 13 |
|
|---|
| 14 |
def handle(self, *args, **options): |
|---|
| 15 |
username = 'BuiltinDjangoAnonymousUser' |
|---|
| 16 |
try: |
|---|
| 17 |
anonuser = User.objects.get(username=username) |
|---|
| 18 |
except User.DoesNotExist: |
|---|
| 19 |
anonuser = User(username=username) |
|---|
| 20 |
|
|---|
| 21 |
anonuser.first_name = 'Anonymous' |
|---|
| 22 |
anonuser.last_name = 'User' |
|---|
| 23 |
anonuser.email = 'invalid@localhost.com' |
|---|
| 24 |
password = "" |
|---|
| 25 |
for n in range(0, 73): |
|---|
| 26 |
password += random.choice(string.printable) |
|---|
| 27 |
|
|---|
| 28 |
algo = 'sha1' |
|---|
| 29 |
salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5] |
|---|
| 30 |
hsh = get_hexdigest(algo, salt, password) |
|---|
| 31 |
anonuser.password = '%s$%s$%s' % (algo, salt, hsh) |
|---|
| 32 |
|
|---|
| 33 |
anonuser.save() |
|---|