Search code examples
phprestsymfonyfosuserbundle

Encryption password FOSUserBundle


I have a symfony project using FOSUSerBundle to manage users , Now I need to access to Database via a Simple Rest Webservice , The encryption in the registration is : Sha512 , How can i get the same hash result as FOS I tried :

hash('sha512',($salt.$password));

and

hash('sha512',($password.$salt));

But it doesnt work ! Any suggestions ?


Solution

  • According to thing class, who encode passwords fos FOSUserBundle, you can understand how Symfony made his encryption

    https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/MessageDigestPasswordEncoder.php

    So you will get something like:

    $password = 'toto';
    $salt = '1234';
    $salted = $password.'{'.$salt.'}';
    $digest = hash('sha512', $salted, true);
    
    for ($i=1; $i<5000; $i++) {
        $digest = hash('sha512', $digest.$salted, true);
    }
    
    $encodedPassword = base64_encode($digest);