Hack Symfony2 database password for admin

Had to get in the admin of a Symfony2 version 2.6 app and I had only code and database access.
I just added some rows to the loginAction() method to get the salt and password for my own plaintext password.

public function loginAction(Request $request) {
    $user = new User();
    $plainPassword = 'YOUR_pass_HERE';
    $encoder = $this->container->get('security.password_encoder');
    echo 'Salt:<br>'.$user->getSalt();
    echo '<br>Password:<br>'.$encoder->encodePassword($user, $plainPassword);

    // loginAction code continues ....


Symfony2 password change
Salt and encoded password for user

Changed the values in the database and login was successful.
You could also flush and persist the new user if you would like, but username needs to be set.
For more help visit the awesome docs page at http://symfony.com/doc/2.6/components/security/authentication.html#using-password-encoders


Author: Michal Zuber

Full stack developer, biker and rollerblader. Owner and developer at https://nevilleweb.sk/ Co-founded http://neville.sk/ Blog at https://michalzuber.wordpress.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s