【发布时间】:2018-02-08 10:19:33
【问题描述】:
我正在使用 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());
但是当我第一次访问我的网站时,我没有 $user 变量。我在哪里可以获得 $user 变量来对我的密码进行编码?
更新我的解决方案
最后,我找到了解决方案。这是我获取编码密码的代码:
$encoded = $app['security.default_encoder']->encodePassword($string, '')
【问题讨论】: