我已經將舊的joomla安裝遷移到了django。雖然密碼哈希值是一個問題。我不得不修改contrib.auth.models中的get_hexdigest以使用額外的if語句來顛倒生成散列的方式。將代碼添加到contrib.auth的最簡潔方法
# 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樹中。在我自己的項目中是否有更簡單的方法來實現這一點?
感謝
備案:就安全性而言,最好先用鹽(見:http://programming.arantius.com/how-to-salt-your-hash) – Jiaaro 2009-11-17 13:22:14
感謝您的支持。我沒有意識到這一點。但在這種情況下,我不能改變它。我正在處理來自Joomla的遺留數據,並以另一種方式進行處理。 – Clarence 2009-11-18 03:36:34