Symfony 2 Logout (UserInterface::eraseCredentials) Symfony 2 Logout (UserInterface::eraseCredentials) symfony symfony

Symfony 2 Logout (UserInterface::eraseCredentials)


No, eraseCredentials() is meant for erasing sensitive data before persisting a token — be it serialization or a database.

To logout a user programmatically, you can use this:

$this->get('security.context')->setToken(null);$this->get('request')->getSession()->invalidate();


In addition to what has been said by Elnur Abdurrakhimov, I suggest to check out this article, explaining how and why we should use UserInterface::eraseCredentials method. Basically, it's not good idea to reuse the password property for storing the plain text password and then to overwrite it with the encoded version, because it's prerequisite error - the programmer may forgot to encode the password and persist the object as is, storing plain text instead of encrypted password.