how to compare a password in symfony2 with fosuserbundle?

this is my fuction code but iam get this error Call to a member function get() on null. so help me please

public function verificarSenhaDefaultAction() {
        $a = "12345678";
        $default = $this->get('security.password_encoder')->encodePassword($this->getUser(), $a);

        if ($this->getUser()->getPassword() == $default):
            return TRUE;
        else:
            Return FALSE;
        endif;
    }

Upvotes: 0

Views: 407

Answers (2)

Cristian Bujoreanu
Cristian Bujoreanu

Reputation: 1167

For friendsofsymfony/UserBundle v2.0:

public function verificarSenhaDefaultAction(User $user, $password) {
    $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);

    return $encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt());
}

Upvotes: 0

Alessandro Minoccheri
Alessandro Minoccheri

Reputation: 35963

You need to call get function from the container like this:

$this->container->get('security.password_encoder')->encodePassword($this->getUser(), $a);

Upvotes: 1

Related Questions