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 ?