1

我已将旧的 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 树中编辑此代码。在我自己的项目中是否有更清洁的方法来做到这一点?

谢谢

4

2 回答 2

6

您最好的选择是滚动自定义身份验证后端并在那里重写 get_hexdigest。我自己从来没有做过,但是关于如何做的文档可以在http://docs.djangoproject.com/en/dev/topics/auth/#authentication-backends找到。

于 2009-11-17T09:04:17.537 回答
0

感谢您的指导。对于需要使用 DJ 密码的其他方式 ( DJangoto Joomla) 的任何人,DJ 格式为Sha1$salt$crypt.

Joomla标准 auth 插件和 joomla 核心JUserHelper没有实现相同的 SHA1 算法,但是在该插件中修补到 joomla.php 相当容易,该插件通常会在':'. 做一个由三部分组成的爆炸'$'和使用salt = [1],比较那个 $encrypted = sha1($salt.$plaintext),匹配那个crypt [2]

于 2011-11-06T22:15:36.620 回答