密码加密不正确

时间:2017-09-20 09:38:17

标签: symfony encryption

我有一个小密码加密问题^^ 在我的数据库中,密码存在,并且必须以这种形式出现:

  

VwBybV5ATQ9RkdvvVZNOlldEEDU9tDjttju7t8l + HeVe4nskHeMpbuCoQsqqORUQKZ1pg7gGtFocpkSIw8N9kA ==

现在我有一个需要为我生成密码的功能。不幸的是,加密并不好,因为这就是我得到的:

  

YmY1NzFkM2VkODYwOGQ1OWFlMTRiZDVkOTc3ZDFkNzQ0ODIzN2U5NWMzNzU0ZjI1Y2U4MTZhYzBiYmExYWJjZTg2Y2JjNzYyM2QwYTJmMDUwYWJiMzQxMjliYjBjYWQxMGZiMzliYzk3OGQwZjYxMGU3Y2E0NjE0ZTkxYzFiYmM =

我的代码:

public function lostpasswordAction(Request $request)
{
    $success = '';
    $string = '';
    $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
    $max = strlen($characters) - 1;
    for ($i = 0; $i < 12; $i++) {
        $string .= $characters[mt_rand(0, $max)];
    }

    if ($request->request->get('email') !== null) {
        $em = $this->getDoctrine()->getManager();
        $user = $em->getRepository('ApplicationSonataUserBundle:User')->findByEmail($request->request->get('email'));

        if (is_null($user)) {
            $response = new JsonResponse('Not Found');
            $response->setStatusCode(Response::HTTP_NOT_FOUND);
            return $response;
        }

        $login = $user[0]->getEmail();
        $password = $string;

        $user[0]->setPassword(hash('sha512',$password));
        $em->persist($user[0]);
        $em->flush();

        $message = \Swift_Message::newInstance()
            ->setSubject('Subject')
            ->setFrom('no-reply@noreply.com')
            ->setTo($request->request->get('email'))
            ->setBody(
                $this->renderView(
                    'emails/lostpassword.txt.twig',
                    array(
                        'login' => $login,
                        'password' => $password
                    )
                ),
                'text/plain'
            );
        $return = $this->get('mailer')->send($message);

        $success = 'Email sent';

        return new JsonResponse($success);
    }

    $response = new JsonResponse('POST only');
    $response->setStatusCode(Response::HTTP_BAD_REQUEST);
    return $response;
}

有人可以帮助我,所以我能得到正确的形状吗?

提前谢谢

0 个答案:

没有答案