Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 516
Asmaa Avatar asked Nov 02 '14 13:11

Asmaa


1 Answers

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);
like image 197
Vincent Barrault Avatar answered Sep 24 '22 15:09

Vincent Barrault