fix #18998

When the backend name is stored in a session, it is first checked whether it is still in the settings. If not, the anonymous user is returned.

Written along with the unit test.