Login

Plaintext password

Author:
yetty
Posted:
October 29, 2013
Language:
Python
Version:
Not specified
Score:
1 (after 1 ratings)

Plaintext password hasher (encoded string: plain$1$mysecretpass).

DANGEROUS!!! Use just if you know what you are doing!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from collections import OrderedDict

from django.utils.translation import ugettext_noop as _
from django.contrib.auth.hashers import BasePasswordHasher


class PlainTextPasswordHasher(BasePasswordHasher):
    algorithm = 'plain'

    def salt(self):
        return ''

    def verify(self, password, encoded):
        return self.encode(password) == encoded

    def encode(self, password, salt=None):
        return "%s$1$%s" % (self.algorithm, password)

    def safe_summary(self, encoded):
        algorithm, iterations, password = encoded.split('$', 2)
        return OrderedDict([
            (_('algorithm'), algorithm),
            (_('iterations'), iterations),
            (_('password'), password),
        ])

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 2 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 2 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 9 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 9 months, 4 weeks ago
  5. Help text hyperlinks by sa2812 10 months, 3 weeks ago

Comments

Please login first before commenting.