我已经将一个旧的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()我还在用户模型中添加了以下内容,以便在登录后更新密码(如果他们使用旧的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树中编辑这段代码。在我自己的项目中,有没有更干净的方法来做到这一点?
谢谢
发布于 2009-11-17 17:04:18
你最好的办法就是创建一个自定义的身份验证后端,并在其中重写get_hexdigest。我自己从来没有做过,但是在http://docs.djangoproject.com/en/dev/topics/auth/#authentication-backends上有关于如何做到这一点的文档。
发布于 2011-11-07 06:15:37
谢谢你的指导。对于任何需要使用DJ密码的人(从DJango到Joomla),DJ格式为Sha1$salt$crypt。
Joomla标准身份验证插件和joomla核心JUserHelper没有实现相同的SHA1算法,但是在该插件中打补丁到joomla.php中是相当容易的,该插件通常会在':'上爆炸。使用'$'进行三部分分解,并使用salt = [1],将其与$encrypted = sha1($salt.$plaintext)进行比较,将其与crypt [2]进行比较。
https://stackoverflow.com/questions/1746994
复制相似问题