Fix bug 2200 and bug 2242 in which there were problems with logging in after
upgrading if you restarted the server first. The new code is less elegant,
but it works correctly. It imposes a database hit on login, but it is
cached, so it only is incurred once.