我正在使用FOSUserBundle将php网站迁移到Django用户模型。
app/config/security.yml
的内容:
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
PHP站点上用户测试的密码/ salt值:
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==
答案 0 :(得分:0)