Ticket #578: auto_admin_md5_fixed.diff
File auto_admin_md5_fixed.diff, 2.0 KB (added by , 19 years ago) |
---|
-
django/models/auth.py
29 29 first_name = meta.CharField(maxlength=30, blank=True) 30 30 last_name = meta.CharField(maxlength=30, blank=True) 31 31 email = meta.EmailField('e-mail address', blank=True) 32 password_md5 = meta.CharField('password', maxlength=32, help_text=" Use an MD5 hash -- not the raw password.")32 password_md5 = meta.CharField('password', maxlength=32, help_text="Password will be automatically encrypted, and won't be visible once the user is added.") 33 33 is_staff = meta.BooleanField('staff status', help_text="Designates whether the user can log into this admin site.") 34 34 is_active = meta.BooleanField('active', default=True) 35 35 is_superuser = meta.BooleanField('superuser status') … … 154 154 raise SiteProfileNotAvailable 155 155 return self._profile_cache 156 156 157 def _module_create_user(username, email, password ):157 def _module_create_user(username, email, password_md5): 158 158 "Creates and saves a User with the given username, e-mail and password." 159 import md5160 password_md5 = md5.new(password).hexdigest()161 159 now = datetime.datetime.now() 162 160 user = User(None, username, '', '', email.strip().lower(), password_md5, False, True, False, now, now) 163 user.save()164 161 return user 165 162 166 163 def _module_make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'): … … 170 167 from random import choice 171 168 return ''.join([choice(allowed_chars) for i in range(length)]) 172 169 170 def _pre_save(self): 171 import md5 172 if (self.password_md5 != md5.new(self.password_md5).hexdigest()): 173 self.password_md5 = md5.new(self.password_md5).hexdigest() 174 173 175 class Message(meta.Model): 174 176 user = meta.ForeignKey(User) 175 177 message = meta.TextField()