Add login feature

Fixed some bugs too, but too tired to separate those from all these changes...