我正在尝试创建一个广告系统。
class Advert {
protected $password;
}
要获得访问权限,用户应提供其广告的密码,而不是其密码帐户。 但是如何使用 Symfony2 安全框架对密码进行编码和检查呢?
最佳答案
在 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';
}
关于Symfony2 如何使用编码密码(不是为了安全),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20719169/