質問

Is there anyway I can load a User from the database with the salt property inside the object?

I'm using FOSUserBundle integrated with FOSFacebookBundle.

I mande one modification that lets a user logs in with Facebook and, if his e-mail is already registered, he binds the facebookId to that existing account.

The thing is, when the updateUser() method is called, the password is updated, and the user can never login using his username and password again.

I need to somehow keep the password at that point. I was thinking of setting the old salt of the user and the actual hashed password again, but the User entity does not come loaded with the salt nor the plain password, only the hashed password.

役に立ちましたか?

解決

Apparently, there was a mistake inside the setFacebookId method:

/**
 * @param string $facebookId
 * @return void
 */
public function setFacebookId($facebookId)
{
    $this->facebookId = $facebookId;
    $this->salt = '';

    if(empty($this->username)) {
        $this->setUsername($facebookId);
    }
}

The salt was being overwritten. Removing that line actually solve the problem:

/**
 * @param string $facebookId
 * @return void
 */
public function setFacebookId($facebookId)
{
    $this->facebookId = $facebookId;

    if(empty($this->username)) {
        $this->setUsername($facebookId);
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top