Symfony2如何使用编码密码(不是为了安全)

use*_*255 3 passwords encode symfony

我正在尝试创建一个广告系统.

class Advert {

    protected $password;

}
Run Code Online (Sandbox Code Playgroud)

要获得访问权限,用户应该提供其广告的密码,而不是他的密码帐户.但是如何使用Symfony2安全框架来编码和检查密码?

Leb*_*nik 6

在Symfony 2.6中可能有更少的版本:

$user = new User();// you object \Acme\DemoBundle\Entity\User from database

$hash = $this->get('security.password_encoder')->encodePassword($user, 'user password');

$user->setPassword($hash);

if( $this->get('security.password_encoder')->isPasswordValid($user, 'user password') ){
    echo 'password equal';
}
Run Code Online (Sandbox Code Playgroud)