Ticket #17944: ReadOnlyPasswordHashWidget.patch

File ReadOnlyPasswordHashWidget.patch, 1.3 KB (added by Stefano Apostolico, 13 years ago)
  • django/contrib/auth/forms.py

     
    2828
    2929        encoded = smart_str(encoded)
    3030
    31         if len(encoded) == 32 and '$' not in encoded:
    32             hasher = get_hasher('unsalted_md5')
     31        try:
     32            if len(encoded) == 32 and '$' not in encoded:
     33                hasher = get_hasher('unsalted_md5')
     34            else:
     35                algorithm = encoded.split('$', 1)[0]
     36                hasher = get_hasher(algorithm)
     37        except ValueError,e:
     38            summary = "<strong>%s</strong>" % ugettext('Unknown password hashing algorithm')
    3339        else:
    34             algorithm = encoded.split('$', 1)[0]
    35             hasher = get_hasher(algorithm)
     40            summary = ""
     41            for key, value in hasher.safe_summary(encoded).iteritems():
     42                summary += "<strong>%(key)s</strong>: %(value)s " % {"key": ugettext(key), "value": value}
    3643
    37         summary = ""
    38         for key, value in hasher.safe_summary(encoded).iteritems():
    39             summary += "<strong>%(key)s</strong>: %(value)s " % {"key": ugettext(key), "value": value}
    40 
    4144        return mark_safe("<div%(attrs)s>%(summary)s</div>" % {"attrs": flatatt(final_attrs), "summary": summary})
    4245
    4346
Back to Top