如何在Silex中编码密码?

时间:2017-08-30 15:52:49

标签: security silex encoder

我正在使用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, '')

1 个答案:

答案 0 :(得分:2)

最好通过给自己一个答案回答你的问题。这使您能够将其标记为已完成。其他用户不会回头看你的问题来为你提供解决方案。

对于这种情况,您可以将我的答案设置为完成,以便关闭问题。

使用此代码加密字符串:

Using reader As New StreamReader(responseStream)
    While True
        Dim filename As String = reader.ReadLine()
        If filename Is Nothing Then
            Exit While
        Else
            dirlist.Add(filename)
            number_of_files++
        End If
    End While
End Using

您还可以使用其他方式在Silex中加密密码。它们可以在here上找到。

以下代码可用于选择其他加密:

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