Migrating from FOSUserBundle to Django

I am trying to migrate a php site using FOSUserBundle to a Django custom model.

Content app/config/security.yml

:

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

      

Password / salt values ​​in custom test on PHP site:

  • password: 3EBoIIMrD73n2y+4hMUpCq2lmJ8tHStrBweonQClP+/Jhmaw7ipLbamQJQfB87Acg45sBH3HlgnpKI+QZN7m/Q==

  • salt: 2n4fxtazv1us0csgg8s880ck4skcskg

  • Password used: amdpower

I tried to create the same hash with this code:

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==

      

What's wrong with the hashing code I've tried? How can I generate the same hash?

Update:

PHP functions:

Solved:

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==

      

+3


source to share


1 answer


Here I have recreated the scenario of how Symfony hashes a password.

http://codepad.org/AhC64q4r



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

0


source







All Articles