dsyak22488 2013-08-28 16:12
浏览 20

密码哈希:创建另一个实体而不重新哈希

Context

My application handles FTP accounts on a server, for several "global users" (each of them has several FTP accounts). When a user registers, he is given his first FTP account, with the same credentials as his global account.

For instance, if a user registers with myusername and mypassword, two entities will be persisted :

  • The main account, with those credentials, and a salt.
  • The first FTP account, which I'd like to have exactly the same credentials (same username, same password, same salt).

Problem

I use a postPersist Doctrine event to create the FTP account. When a user registers (is persisted), the event automatically creates a FTP account entity associated to the user, with the same credentials. Here's a code sample from postPersist :

// $user is the entity passed through the event args ($args->getEntity()).
$ftp = new FTPAccount();
$ftp->setUsername($user->getUsername());
$ftp->setSalt($user->getSalt());
$ftp->setPassword($user->getPassword());

Note : both entities use the same password encoder, that's why copying the password hash and the salt is appropriate.

But here's the problem : Symfony considers $user->getPassword() as cleartext, and therefore rehashes it once the FTP account entity is persisted. This is due to this part of my security.yml file :

security:
    encoders:
        FTPAccount: sha512

Considering the following facts :

  • I cannot get the user's cleartext password in postPersist, it's already hashed.
  • I do not always have the hashed password (here, I have it because it is the first FTP account)

Is there a way I could ask Symfony to bypass password hashing for this entity instance ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来
    • ¥15 用stata实现聚类的代码
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan