我已将旧的 joomla 安装迁移到 django。密码哈希是一个问题。我不得不修改 contrib.auth.models 中的 get_hexdigest 以获得额外的 if 语句来反转生成哈希的方式。
# Custom for Joomla
if algorithm == 'joomla':
return md5_constructor(raw_password + salt).hexdigest()
# Djangos original md5
if algorithm == 'md5':
return md5_constructor(salt + raw_password).hexdigest()
我还在 User 模型中添加了以下内容,以便在登录后更新密码(如果它们具有旧的 joomla 样式):
# Joomla Backwards compat
algo, salt, hsh = self.password.split('$')
if algo == 'joomla':
is_correct = (hsh == get_hexdigest(algo, salt, raw_password))
if is_correct:
# Convert the password to the new more secure format.
self.set_password(raw_password)
self.save()
return is_correct
一切正常,但我不想直接在 django 树中编辑此代码。在我自己的项目中是否有更清洁的方法来做到这一点?
谢谢