import django.contrib.auth.hashers from django.utils.crypto import pbkdf2 class PBKDF2PasswordHasher(django.contrib.auth.hashers.PBKDF2PasswordHasher): """ A subclass of PBKDF2PasswordHasher for discourse. """ algorithm = "pbkdf2_sha256_dis" iterations = 64000 def encode(self, password, salt, iterations=None): assert password is not None assert salt and '$' not in salt iterations = iterations or self.iterations hash = pbkdf2(password, salt, iterations, digest=self.digest) hash = ''.join(map(lambda s: ('0' + hex(s)[2:])[-2:], hash)) return "%s$%d$%s$%s" % (self.algorithm, iterations, salt, hash)