我正在将带有 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 函数是:
FOSUserBundle:https ://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Model/UserManager.php#L180
Symfony:https ://github.com/symfony/symfony/tree/master/src/Symfony/Component/Security/Core/Encoder
解决了:
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==