Ticket #9444: createanonuser.py

File createanonuser.py, 1002 bytes (added by Digitalxero, 16 years ago)

The actual createanonuser Management command

Line 
1"""
2Management utility to create anonuser.
3"""
4import random
5import string
6
7
8from django.contrib.auth.models import User, get_hexdigest
9
10class 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()
Back to Top