3

我正在将带有 FOSUserBundle 的 php 站点迁移到 Django 用户模型。

的内容app/config/security.yml

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

来自 PHP 站点的用户测试的密码/盐值:

  • 密码:3EBoIIMrD73n2y+4hMUpCq2lmJ8tHStrBweonQClP+/Jhmaw7ipLbamQJQfB87Acg45sBH3HlgnpKI+QZN7m/Q==
  • 盐:2n4fxtazv1us0csgg8s880ck4skcskg
  • 使用的密码是amdpower

我试图用这段代码生成相同的哈希:

raw_password = 'amdpower'
salt = '2n4fxtazv1us0csgg8s880ck4skcskg'

salted = '%s{%s}' % (raw_password, salt)
digest =  hashlib.sha512(salted).digest()
for i in range(5000):
   digest = hashlib.sha512(digest).digest()
print base64.b64encode(digest)
>>> wqgbbFZ/IPvwZktbmYz7inffofmT5HbRNf04BQ+w33Jgman8uVYbjWyiKzfp5EIFX2wqYGOb7hRzi5BdZlzDKw==

我尝试过的哈希码有什么问题?如何生成相同的哈希?

更新:

PHP 函数是:

解决了:

raw_password = 'amdpower'
salt = '2n4fxtazv1us0csgg8s880ck4skcskg'

salted = '%s{%s}' % (raw_password, salt)
digest =  hashlib.sha512(salted).digest()
for i in range(4999):
    digest = hashlib.sha512('%s%s' % (digest, salted)).digest()
print base64.b64encode(digest)
>>> 3EBoIIMrD73n2y+4hMUpCq2lmJ8tHStrBweonQClP+/Jhmaw7ipLbamQJQfB87Acg45sBH3HlgnpKI+QZN7m/Q==
4

1 回答 1

0

在这里,我重新创建了 Symfony 如何散列密码的场景。

http://codepad.org/AhC64q4r

Now it's all about converting it to python, which I know you can do it Juan :)

于 2013-02-02T20:12:49.380 回答