Theodore Enderby
Theodore Enderby

Reputation: 642

Transferring FOS_USERS between symfony projects

I've been given the task of transferring a user database from one FOSUserBundle/Symfony project to another.

My sample user from the old project has been transferred over to the new project containing all the same fields [ salt, password, etc ], yet I'm unable to login using the same username / password combination.

What else goes into the password storage in FOSUserBundle that would make the password + salt combination invalid between projects, and how can I transfer the raw data of the old project into the new project.

My input is a JSON file with all the user table details. I am importing this through PHP, and creating and persisting user objects in a loop without using fos_user.user_manager.

foreach ($obj as $userData) {
    if (isset($userData['personalDetails'])) {
        if (isset($userData['personalDetails']['firstName'])) {
           /** @var User $user */
           $user = new User();
           $user->setId($userData['id']);
           $user->setSalt($userData['salt']);
           $user->setPassword($userData['password']);
           $user->setUsername($userData['email']);
           $user->setEmail($userData['email']);
           $user->setEnabled($userData['enabled']);
           $user->setExpired($userData['expired']);
           $user->getPersonalDetails()->setFirstName($userData['personalDetails']['firstName']);
           $user->getPersonalDetails()->setLastName($userData['personalDetails']['lastName']);

           $user->setFacebookId($userData['facebookId']);
           $user->setFacebookAccessToken($userData['facebookAccessToken']);
           $user->setGoogleId($userData['googleId']);
           $user->setGoogleAccessToken($userData['googleAccessToken']);

           $this->getDoctrine()->getManager()->persist($user);
            }
        }
    }

Upvotes: 0

Views: 29

Answers (1)

Stan Sarr
Stan Sarr

Reputation: 243

You can use the same table (FOSUSER) with your new project or just dump your table and move it to your new database. If you do that, you have to keep the same "Encoder configuration" on the security as the old project. The UserPassword only need the salt, the PlainPassword and user the encoded user to create the hashed password. If you have the same configuration in the configuration in the new project like the old one everything will be ok. Hope I help you .. Let us know.

    //Security.yml
    security:
        encoders:
            Site\UserBundle\Entity\User: sha512
            FOS\UserBundle\Model\UserInterface: sha512

Upvotes: 1

Related Questions