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

标签 symfony passwords encode

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

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/

相关文章:

c# - 使用 salt 保护密码散列,但如何将其存储在本地 cookie 中呢?

在 C 中比较密码的两个字符字符串

SVN加密密码存储

python-3.x - 'cp93 2' codec can' t 编码字符 '\u98c8' 在位置 32 : illegal multibyte sequence

mysql - Flutter-将列表转换为json并存储在MYSQL数据库中

forms - 使用 form_errors(form) plus 显示 symfony2 中每个字段的所有错误

php - 如何从 Symfony2 中的包覆盖全局 Monolog 配置

symfony - 在 symfony 3 中添加 Google API 客户端库

作为 URL 的参数的 Java Servlet getParameter

Symfony2 Doctrine,设置一个多对多自引用关系的页面