Hashed Passwords Using Symfony's AliceBundle
1 min read

Hashed Passwords Using Symfony's AliceBundle

When using AliceBundle for fixtures in my Symfony project, I ran into an issue creating hashed passwords for users.

Some things I tried based on brief research that still didn't provide a solution:

  • The password() generator helper wasn't sufficient, since it just creates a plain text password.
  • Symfony didn't encode the password for me, because I am not using the plainPassword field (no FOSUserBundle or anything, handling this on my own).
  • Adding an already-hashed password to the YAML file gave me "undefined variable" errors.

In the end, what worked for me was to use the already-hashed password in the YAML file, and also making sure to both wrap the password in single quotes, and to escape any dollar signs in the password with backslashes. Escaping the dollar signs prevents any variable reference parsing in YAML.

If you need dynamically-generated passwords in a manually-controlled hashing strategy situation, I'm still not sure what the best solution would be. Do you? Share it with me on Twitter!