Generate Password Hash Using Console Command in Symfony 7

Generate Password Hash Using Console Command in Symfony 7

Symfony provides many pre-built commands designed to assist with development and testing processes. Among these commands is a built-in command specifically designed for generating password hashes according to the security configuration. It can be useful when setting up authentication for in-memory users or updating passwords stored in the database during the development phase of the application. This tutorial explains how to generate password hash using console command in Symfony 7.

The security:hash-password command takes a plain-text password as an argument and then generates a secure hashed representation of the password according to configuration specified in the security.yaml file.

Suppose you want to hash the password pwd123. The following console command demonstrates how to achieve this:

php bin/console security:hash-password pwd123

Output example:

--------------- ----------------------------------------------------------------- 
  Key             Value
 --------------- -----------------------------------------------------------------
  Hasher used     Symfony\Component\PasswordHasher\Hasher\MigratingPasswordHasher
  Password hash   $2y$13$nx3NLGjxKnO42KNdKCQR3ek9P3UpolB0yhGmY3Gic9LLfAo24BIBC
 --------------- -----------------------------------------------------------------

 ! [NOTE] Self-salting hasher used: the hasher generated its own built-in salt.

Leave a Comment

Cancel reply

Your email address will not be published.