将 ASP.NET 会员用户迁移到 Django 而不重置密码?
我有一个系统,部分是由其他人编写的,对于这样一个小应用程序来说,维护完全是一场噩梦。我终于得到了改变,这证明重写可怕的混乱是合理的,所以我将它转移到 Django。
在我尝试之前,我一直在尝试将密码哈希和盐移到 Django 身份验证表 [sha1]$[salt]$[hash] 中,但无法使其正确哈希(重置密码不是确实是一个选择)。
到目前为止,我已经发现了以下内容:
- ASP.NET 将哈希存储为 Base64 字符串并使用 Base64 盐(在哈希之前)
- 我显然可以将 Base64 哈希反转为字节数组
- Django 使用十六进制摘要,我尝试过BitConverter.ToString 但它们的哈希值不同
我在这里打的是一场失败的战斗吗?在 Django 中编写一个像 ASP.NET 那样进行哈希处理的方法会更好吗?
任何帮助表示赞赏,
托马斯
I've got a system that was partially written by someone else and is a complete maintenance nightmare for such a small app. I've finally been given changes which justifies just rewriting the horrible mess so I am moving it to Django.
Before I take the plunge, I've been trying to move over the password hash and salt into the Django auth tables [sha1]$[salt]$[hash] but can't get it to hash properly (resetting passwords isn't really an option).
Here is what I've been able to find out so far:
- ASP.NET stores the hash as base64 string and uses a base64 salt (before hash)
- I can obviously reverse the base64 hash to a byte array
- Django uses a hexdigest, I tried BitConverter.ToString but they hash differently
Am I fighting a losing battle here? Would it be better to write a method in Django to hash as ASP.NET does?
Any help appreciated,
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
避免中间重置密码的唯一真正选择是:
您还可以尝试对密码进行逆向工程,但如果您成功做到这一点,那么在我看来,哈希算法就毫无意义了。
The only real options you have here to avoid a password reset in the middle is to:
You could also attempt to reverse engineer the passwords, but if you're successful in doing that it sort of makes the hashing algorithm pointless IMO.
使用以下 Django 密码哈希器创建一个新模块来处理 ASP.net (sha1) 密码:
将模块名称添加到 PASSWORD_HASHERS 列表中的设置文件中(请参阅 https://docs.djangoproject.com/en/1.4/topics/auth/ 了解详细信息)。
将 ASP.net 盐和密码迁移到 Django 密码字段,如下所示:
然后,用户可以使用现有的 ASP.net 密码登录到您的 Django 应用程序。一旦他们成功登录,Django将自动将他们的密码升级到最新的算法,例如PBKDF2。
Create a new module with the following Django password hasher to handle ASP.net (sha1) passwords:
Add the module name to your settings file in the PASSWORD_HASHERS list (see https://docs.djangoproject.com/en/1.4/topics/auth/ for details).
Migrate the ASP.net salt and password into the Django password field like this:
Users can then login to your Django app with their existing ASP.net passwords. Once they've logged in successfully, Django will automatically upgrade their passwords to the latest algorithm, e.g. PBKDF2.