Cleanup and login

The merge contains some preparation for login feature and simple implementation of it. It needs to get polished a bit... But the stack of patches started to be too big and I decided to push.