2017-08-30 143 views
2

我正在寫一個Silex的登錄應用程序,但我有一個Silex密碼編碼器的問題。我的硅石文檔閱讀,並得到一些像這樣的代碼:如何在Silex中編碼密碼?

// find the encoder for a UserInterface instance 
$encoder = $app['security.encoder_factory']->getEncoder($user); 

// compute the encoded password for foo 
$password = $encoder->encodePassword('foo', $user->getSalt()); 

但是,當我訪問我的網站在第一時間,我沒有$用戶varirable。我在哪裏可以獲得$用戶可變編碼我的密碼?

更新我的解決方案

最後,我找到了解決辦法。這是我的密碼編碼:

$encoded = $app['security.default_encoder']->encodePassword($string, '') 

回答

1

最好通過給自己一個答案來回答你的問題。這使您能夠將其標記爲已完成。其他用戶不會回想起你的問題給你一個解決方案。

對於這種情況,您可以將我的答案設置爲完成,以便問題關閉。

使用此代碼來加密字符串:

$encoded = $app['security.default_encoder']->encodePassword($string, '') 

您還可以使用其他方式的Silex加密密碼。他們可以通過here找到。

以下代碼可被用來選擇另一加密:

$app['security.default_encoder'] = function ($app) { 
    return $app['security.encoder.pbkdf2']; 
};