2014-11-02 284 views
4

我有一個使用FOSUSerBundle管理用戶的symfony項目,現在我需要通過簡單的休息Web服務訪問數據庫, 註冊中的加密是:Sha512,我怎樣才能得到與FOS相同的哈希結果 我想:加密密碼FOSUserBundle

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

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

但它不工作!有什麼建議麼 ?

回答

10

據事類,誰編碼密碼FOS FOSUserBundle,你可以理解的Symfony如何使自己的加密

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

所以你會得到這樣的:

$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);