我似乎已经解决了这个问题,我在我们的 django 1.3 机器中找到了一个要在 md5crypt 中加密的模块,然后转到我的 django /usr/local/lib/python2.7/dist-packages/django/contrib/auth/ hashers.py 文件并定义了一个新的哈希类:
#imported md5crypt.py module that I moved to /usr/local/lib/python2.7/dist-packages/django/contrib/auth/
from django.contrib.auth import md5crypt
class MD5CryptPasswordHasher(BasePasswordHasher):
"""
The Salted MD5crypt password hashing algorithm
"""
algorithm = "md5crypt"
def encode(self, password, salt):
assert password is not None
assert salt and '$' not in salt
cryptedpassword = md5crypt.md5crypt(force_bytes(password), force_bytes(salt))
cryptedpassword = cryptedpassword.split('$',2)[2]
#change from $1$ to md5crypt$
return "%s$%s" % (self.algorithm, cryptedpassword)
def verify(self, password, encoded):
algorithm, salt, hash = encoded.split('$', 2)
assert algorithm == self.algorithm
encoded_2 = self.encode(password, salt)
return constant_time_compare(encoded, encoded_2)
def safe_summary(self, encoded):
algorithm, salt, hash = encoded.split('$', 2)
assert algorithm == self.algorithm
return OrderedDict([
(_('algorithm'), algorithm),
(_('salt'), mask_hash(salt, show=2)),
(_('hash'), mask_hash(hash)),
])
我的密码哈希器 settings.py:
PASSWORD_HASHERS=(
'django.contrib.auth.hashers.MD5CryptPasswordHasher',
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
'django.contrib.auth.hashers.BCryptPasswordHasher',
'django.contrib.auth.hashers.SHA1PasswordHasher',
'django.contrib.auth.hashers.MD5PasswordHasher',
'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher',
'django.contrib.auth.hashers.CryptPasswordHasher',
)
出于安全原因,我无法与您共享模块 md5crypt.py,因为我没有此权限。