【发布时间】:2013-01-09 06:46:15
【问题描述】:
我将用户从其他站点迁移到 django 站点。旧网页有带盐的 md5 密码,我正在编写一个自定义散列算法,以便用户可以使用他们的旧密码进行身份验证。
当我尝试以旧用户身份登录时:
Unknown password hashing algorithm 'my_hashed_password'. Did you specify it in the PASSWORD_HASHERS setting?
这是我的密码哈希
class FallbackMD5PasswordHasher(BasePasswordHasher):
algorithm = "fallback_md5"
def salt(self):
return 'my_salt'
def encode(self, password):
return hashlib.md5(self.salt() + password).hexdigest()
def verify(self, password, encoded):
encoded_2 = self.encode(password, '')
return constant_time_compare(encoded, encoded_2)
def safe_summary(self, encoded):
return SortedDict([
(_('algorithm'), self.algorithm),
(_('hash'), mask_hash(encoded, show=3)),
])
那是我的 settings.py
PASSWORD_HASHERS = (
'lfs_custom.hasher.FallbackMD5PasswordHasher',
'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.CryptPasswordHasher',
)
请提供一些信息来解决这个问题 :) 我不知道为什么它不起作用。
【问题讨论】:
-
字符串“my_hashed_password”从何而来?你能查一下项目文件吗?
-
该字符串是我数据库中的哈希密码,登录时返回错误。
标签: django authentication hash passwords