Ticket #578: auto_admin_md5_fixed.diff

File auto_admin_md5_fixed.diff, 2.0 KB (added by Hein-Pieter van Braam <hp@…>, 19 years ago)
  • django/models/auth.py

     
    2929    first_name = meta.CharField(maxlength=30, blank=True)
    3030    last_name = meta.CharField(maxlength=30, blank=True)
    3131    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.")
    3333    is_staff = meta.BooleanField('staff status', help_text="Designates whether the user can log into this admin site.")
    3434    is_active = meta.BooleanField('active', default=True)
    3535    is_superuser = meta.BooleanField('superuser status')
     
    154154                    raise SiteProfileNotAvailable
    155155        return self._profile_cache
    156156
    157     def _module_create_user(username, email, password):
     157    def _module_create_user(username, email, password_md5):
    158158        "Creates and saves a User with the given username, e-mail and password."
    159         import md5
    160         password_md5 = md5.new(password).hexdigest()
    161159        now = datetime.datetime.now()
    162160        user = User(None, username, '', '', email.strip().lower(), password_md5, False, True, False, now, now)
    163         user.save()
    164161        return user
    165162
    166163    def _module_make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'):
     
    170167        from random import choice
    171168        return ''.join([choice(allowed_chars) for i in range(length)])
    172169
     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
    173175class Message(meta.Model):
    174176    user = meta.ForeignKey(User)
    175177    message = meta.TextField()
Back to Top