编码明文Symfony 4

时间:2018-06-02 11:15:54

标签: symfony4

我有两个控制器SecurityController& UserController的

public function login(Request $request, AuthenticationUtils $authenticationUtils)
{
    // get the login error if there is one
    $error = $authenticationUtils->getLastAuthenticationError();

    // last username entered by the user
    $lastUsername = $authenticationUtils->getLastUsername();

    return $this->render('security/index.html.twig', array(
        'last_username' => $lastUsername,
        'error'         => $error,
    ));
}
public function register(UserPasswordEncoderInterface $encoder)
{
    // whatever *your* User object is
    $user = new App\Entity\User();
    $plainPassword = 'ryanpass';
    $encoded = $encoder->encodePassword($user, $plainPassword);

    $user->setPassword($encoded);
}

用户控制器

public function editUser(Request $request, User $user, UserPasswordEncoderInterface $encoder): Response
{   $plainPassword = 'ryanpass';
    $encoded = $encoder->encodePassword($user, $plainPassword);
    $user->setPassword($encoded);

    $form = $this->createForm(User1Type::class, $user);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $this->getDoctrine()->getManager()->flush();

        return $this->redirectToRoute('user_edit', ['id' => $user->getId()]);
    }

    return $this->render('user/edit.html.twig', [
        'user' => $user,
        'form' => $form->createView(),
    ]);
}

当我使用SecurityController通过登录寄存器对plainpassword进行编码时,一切正常,存储在数据库中的HASH与密码匹配。

但是,如果我尝试使用新字符串处理此明文,则HASH正在更新但与所谓的纯文本不匹配。

任何想法都会非常感激。

0 个答案:

没有答案